ck_pojie.Pojie.sign()   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 27
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 22
nop 1
dl 0
loc 27
rs 9.352
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
"""
3
cron: 53 11 * * *
4
new Env('吾爱破解');
5
"""
6
7
import requests
8
from bs4 import BeautifulSoup
9
10
from notify_mtr import send
11
from utils import get_data
12
13
14
class Pojie:
15
    def __init__(self, check_items):
16
        self.check_items = check_items
17
18
    @staticmethod
19
    def sign(cookie):
20
        session = requests.session()
21
        res = ""
22
        headers = {
23
            "Cookie": cookie,
24
            "ContentType": "text/html;charset=gbk",
25
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) "
26
            "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
27
        }
28
        session.put(
29
            "https://www.52pojie.cn/home.php?mod=task&do=apply&id=2", headers=headers
30
        )
31
        response = session.put(
32
            "https://www.52pojie.cn/home.php?mod=task&do=draw&id=2", headers=headers
33
        )
34
        soup = BeautifulSoup(response.text, "html.parser")
35
        msg = soup.find("div", id="messagetext").find("p").text
36
        if "您需要先登录才能继续本操作" in msg:
37
            res += "Cookie 失效"
38
        elif "恭喜" in msg:
39
            res += "签到成功"
40
        elif "不是进行中的任务" in msg:
41
            res += "不是进行中的任务"
42
        else:
43
            res += "签到失败"
44
        return res
45
46
    def main(self):
47
        msg_all = ""
48
        for i, check_item in enumerate(self.check_items, start=1):
49
            cookie = check_item.get("cookie")
50
            sign_msg = self.sign(cookie)
51
            msg = f"账号 {i} 签到状态: {sign_msg}"
52
            msg_all += msg + "\n\n"
53
        return msg_all
54
55
56
if __name__ == "__main__":
57
    _data = get_data()
58
    _check_items = _data.get("POJIE", [])
59
    result = Pojie(check_items=_check_items).main()
60
    send("吾爱破解", result)
61