ck_juejin.Juejin.sign()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
"""
3
cron: 7 11 * * *
4
new Env('掘金');
5
"""
6
7
import requests
8
9
from notify_mtr import send
10
from utils import get_data
11
12
13
class Juejin:
14
    def __init__(self, check_items):
15
        self.check_items = check_items
16
        self.base_url = "https://api.juejin.cn/"
17
        self.headers = {
18
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
19
            "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36"
20
        }
21
22
    def sign(self, cookie):
23
        sign_url = f"{self.base_url}growth_api/v1/check_in"
24
        return requests.post(
25
            url=sign_url, headers=self.headers, cookies={"Cookie": cookie}
26
        ).json()
27
28
    def lottery(self, cookie):
29
        lottery_url = f"{self.base_url}growth_api/v1/lottery/draw"
30
        return requests.post(
31
            url=lottery_url, headers=self.headers, cookies={"Cookie": cookie}
32
        ).json()
33
34
    def main(self):
35
        msg_all = ""
36
        for i, check_item in enumerate(self.check_items, start=1):
37
            cookie = str(check_item.get("cookie"))
38
            sign_msg = self.sign(cookie)["err_msg"]
39
            lottery_msg = self.lottery(cookie)["err_msg"]
40
            msg = (
41
                f"账号 {i}"
42
                + "\n------ 掘金签到结果 ------\n"
43
                + sign_msg
44
                + "\n------ 掘金抽奖结果 ------\n"
45
                + lottery_msg
46
            )
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("JUEJIN", [])
54
    result = Juejin(check_items=_check_items).main()
55
    send("掘金", result)
56