forked from liuyuhe666/flzt-auto-checkin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
91 lines (76 loc) · 2.42 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import requests
import json
from dotenv import load_dotenv
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0'
}
def load_env():
load_dotenv()
env = os.environ
return dict(env)
def login(url, email, password):
data = {
'email': email,
'passwd': password
}
response = requests.post(url=url, data=data, headers=headers)
if response.status_code != 200:
return None
try:
data = json.loads(response.text)
return data['token']
except:
print('登录失败')
return None
def checkin(url, token):
headers['Access-Token'] = token
response = requests.get(url=url, headers=headers)
try:
data = json.loads(response.text)
print(data['result'])
except:
print('签到失败')
def get_user_info(url, token):
headers['Access-Token'] = token
response = requests.get(url=url, headers=headers)
try:
data = json.loads(response.text)
return data['result']['data']
except:
print('获取用户信息失败')
return None
def convert_traffic(url, token, traffic):
headers['Access-Token'] = token
params = {
'traffic': str(traffic)
}
response = requests.get(url=url, headers=headers, params=params)
try:
data = json.loads(response.text)
print(data['msg'])
except:
print('流量转换失败')
def main():
env = load_env()
login_url = env['BASE_URL'] + '/api/token'
checkin_url = env['BASE_URL'] + '/api/user/checkin'
user_info_url = env['BASE_URL'] + '/api/user/info'
convert_traffic_url = env['BASE_URL'] + '/api/user/koukanntraffic'
email = env['EMAIL']
password = env['PASSWORD']
token = login(url=login_url, email=email, password=password)
if token is not None:
checkin(url=checkin_url, token=token)
data = get_user_info(url=user_info_url, token=token)
if data is None:
return
traffic = int(int(data['transfer_checkin']) / 1024 / 1024)
print(f'签到获得的剩余流量: {traffic}MB')
if traffic > 0:
convert_traffic(url=convert_traffic_url,
token=token, traffic=traffic)
else:
print('没有需要转换的流量,明天再来吧!')
if __name__ == '__main__':
main()