ck_picacomic   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 78
dl 0
loc 97
rs 10
c 0
b 0
f 0
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A Picacomic.main() 0 9 2
A Picacomic.generate_headers() 0 31 3
A Picacomic.sign() 0 25 3
A Picacomic.__init__() 0 2 1
1
# -*- coding: utf-8 -*-
2
"""
3
cron: 45 5 * * *
4
new Env('哔咔漫画');
5
"""
6
7
import hashlib
8
import hmac
9
import random
10
import string
11
import time
12
13
import requests
14
15
from notify_mtr import send
16
from utils import get_data
17
18
19
class Picacomic:
20
    def __init__(self, check_items):
21
        self.check_items = check_items
22
23
    @staticmethod
24
    def generate_headers(path, data=None, token=None):
25
        api_key = "C69BAF41DA5ABD1FFEDC6D2FEA56B"
26
        api_secret = "~d}$Q7$eIni=V)9\\RK/P.RM4;9[7|@/CA}b~OW!3?EV`:<>M7pddUBL5n|0/*Cn"
27
        current_time = str(int(time.time()))
28
        nonce = "".join(random.choices(string.ascii_lowercase + string.digits, k=32))
29
        raw = path + current_time + nonce + "POST" + api_key
30
        raw = raw.lower()
31
        h = hmac.new(api_secret.encode(), digestmod=hashlib.sha256)
32
        h.update(raw.encode())
33
        signature = h.hexdigest()
34
        headers = {
35
            "api-key": api_key,
36
            "accept": "application/vnd.picacomic.com.v1+json",
37
            "app-channel": "2",
38
            "app-version": "2.2.1.2.3.3",
39
            "app-uuid": "defaultUuid",
40
            "app-platform": "android",
41
            "app-build-version": "44",
42
            "User-Agent": "okhttp/3.8.1",
43
            "image-quality": "original",
44
            "time": current_time,
45
            "nonce": nonce,
46
            "signature": signature,
47
        }
48
49
        if data is not None:
50
            headers["Content-Type"] = "application/json; charset=UTF-8"
51
        if token is not None:
52
            headers["authorization"] = token
53
        return headers
54
55
    def sign(self, email, password):
56
        try:
57
            data = {"email": email, "password": password}
58
            sign_headers = self.generate_headers(path="auth/sign-in", data=data)
59
            sign_res = requests.post(
60
                "https://picaapi.picacomic.com/auth/sign-in",
61
                json={"email": email, "password": password},
62
                headers=sign_headers,
63
                timeout=60,
64
            ).json()
65
            token = sign_res.get("data", {}).get("token")
66
67
            punch_headers = self.generate_headers(path="users/punch-in", token=token)
68
            res = requests.post(
69
                "https://picaapi.picacomic.com/users/punch-in",
70
                headers=punch_headers,
71
                timeout=60,
72
            ).json()
73
            if res.get("data", {}).get("res", {}).get("status", {}) == "ok":
74
                msg = "打卡成功"
75
            else:
76
                msg = "重复签到"
77
        except Exception as e:
78
            msg = str(e)
79
        return msg
80
81
    def main(self):
82
        msg_all = ""
83
        for check_item in self.check_items:
84
            email = check_item.get("email")
85
            password = check_item.get("password")
86
            sign_msg = self.sign(email, password)
87
            msg = f"帐号信息: {email}\n签到状态: {sign_msg}"
88
            msg_all += msg + "\n\n"
89
        return msg_all
90
91
92
if __name__ == "__main__":
93
    _data = get_data()
94
    _check_items = _data.get("PICACOMIC", [])
95
    result = Picacomic(check_items=_check_items).main()
96
    send("哔咔漫画", result)
97