ck_youdao.YouDao.sign()   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 44
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 34
nop 2
dl 0
loc 44
rs 9.064
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
"""
3
cron: 18 20 * * *
4
new Env('有道云笔记');
5
"""
6
7
import time
8
9
import requests
10
11
from notify_mtr import send
12
from utils import get_data
13
14
15
class YouDao:
16
    def __init__(self, check_items):
17
        self.check_items = check_items
18
19
    @staticmethod
20
    def get_space(cookie):
21
        url = "https://note.youdao.com/yws/mapi/user?method=get"
22
        headers = {"Cookie": cookie}
23
        res = requests.get(url=url, headers=headers).json()
24
        return 0 if res.get("q") is None else res.get("q")
25
26
    def sign(self, cookie):
27
        msg = f"签到前空间: {int(self.get_space(cookie))//1048576}M\n"
28
        ad = 0
29
30
        headers = {"Cookie": cookie}
31
        r = requests.get(
32
            "http://note.youdao.com/login/acc/pe/getsess?product=YNOTE", headers=headers
33
        )
34
        c = "".join(f"{key}={value};" for key, value in r.cookies.items())
35
        headers = {"Cookie": c}
36
37
        r2 = requests.post(
38
            "https://note.youdao.com/yws/api/daupromotion?method=sync", headers=headers
39
        )
40
        if "error" not in r2.text:
41
            checkin1 = requests.post(
42
                "https://note.youdao.com/yws/mapi/user?method=checkin", headers=headers
43
            )
44
            time.sleep(1)
45
            checkin2 = requests.post(
46
                "https://note.youdao.com/yws/mapi/user?method=checkin",
47
                {"device_type": "android"},
48
                headers=headers,
49
            )
50
51
            for _ in range(3):
52
                resp = requests.post(
53
                    "https://note.youdao.com/yws/mapi/user?method=adRandomPrompt",
54
                    headers=headers,
55
                )
56
                ad += resp.json()["space"] // 1048576
57
                time.sleep(2)
58
59
            if "reward" in r2.text:
60
                s = self.get_space(cookie)
61
                msg += f"签到后空间: {int(s)//1048576}M\n"
62
                sync = r2.json()["rewardSpace"] // 1048576
63
                checkin_1 = checkin1.json()["space"] // 1048576
64
                checkin_2 = checkin2.json()["space"] // 1048576
65
                space = str(sync + checkin_1 + checkin_2 + ad)
66
                msg += f"获得空间:{space}M, 总空间:{int(s)//1048576}M"
67
        else:
68
            msg += f"错误 {str(r2.json())}"
69
        return msg
70
71
    def main(self):
72
        msg_all = ""
73
        for check_item in self.check_items:
74
            cookie = check_item.get("cookie")
75
            msg = self.sign(cookie)
76
            msg_all += msg + "\n\n"
77
        return msg_all
78
79
80
if __name__ == "__main__":
81
    _data = get_data()
82
    _check_items = _data.get("YOUDAO", [])
83
    result = YouDao(check_items=_check_items).main()
84
    send("有道云笔记", result)
85