ck_enshan   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Enshan.__init__() 0 2 1
A Enshan.sign() 0 20 2
A Enshan.main() 0 8 2
1
# -*- coding: utf-8 -*-
2
"""
3
cron: 1 15 * * *
4
new Env('恩山论坛');
5
"""
6
7
import re
8
import time
9
10
import requests
11
12
from notify_mtr import send
13
from utils import get_data
14
15
16
class Enshan:
17
    def __init__(self, check_items):
18
        self.check_items = check_items
19
20
    @staticmethod
21
    def sign(cookie):
22
        url = (
23
            "https://www.right.com.cn/FORUM/home.php?mod=spacecp&ac=credit&showcredit=1"
24
        )
25
        headers = {
26
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
27
            "AppleWebKit/537.36 (KHTML, like Gecko) "
28
            "Chrome/92.0.4515.131 Safari/537.36",
29
            "Cookie": cookie,
30
        }
31
        session = requests.session()
32
        response = session.get(url, headers=headers)
33
        try:
34
            coin = re.findall("恩山币: </em>(.*?)nb &nbsp;", response.text)[0]
35
            point = re.findall("<em>积分: </em>(.*?)<span", response.text)[0]
36
            res = f"恩山币:{coin}\n积分:{point}"
37
        except Exception as e:
38
            res = str(e)
39
        return res
40
41
    def main(self):
42
        msg_all = ""
43
        for i, check_item in enumerate(self.check_items, start=1):
44
            cookie = str(check_item.get("cookie"))
45
            msg = f"账号{i}\n------ 签到结果 ------\n{self.sign(cookie)}"
46
            time.sleep(1)
47
            msg_all += msg + "\n\n"
48
        return msg_all
49
50
51
if __name__ == "__main__":
52
    _data = get_data()
53
    _check_items = _data.get("ENSHAN", [])
54
    result = Enshan(check_items=_check_items).main()
55
    send("恩山论坛", result)
56