-
Notifications
You must be signed in to change notification settings - Fork 51
/
base_user.py
81 lines (68 loc) · 2.85 KB
/
base_user.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
import asyncio
from web_hub import WebHub, HostWebHub
from states import UserStates
from statistic import Statistics
import printer
from config_loader import ConfigLoader
class BaseUser:
def __init__(self, user_id, dict_user, dict_bili, task_control, high_concurency):
if high_concurency:
self.webhub = HostWebHub(user_id, dict_user, dict_bili)
else:
self.webhub = WebHub(user_id, dict_user, dict_bili)
self.statistics = Statistics()
self.user_id = user_id
self.user_name = dict_user['username']
self.user_password = dict_user['password']
self.task_control = task_control
self.state = UserStates(user_id, self.user_name)
def printer_with_id(self, list_msg, tag_time=False):
list_msg[0] += f'(用户id:{self.user_id} 用户名:{self.user_name})'
printer.info(list_msg, tag_time)
def write_user(self, dict_new):
self.webhub.set_status(dict_new)
ConfigLoader().write_user(dict_new, self.user_id)
async def get_statistic(self):
await asyncio.sleep(0)
work_state, time_state = self.print_state()
self.printer_with_id([f'小黑屋状态: {work_state}'], True)
self.printer_with_id([f'工作状态: {time_state}'], True)
self.statistics.getlist()
self.statistics.getresult()
async def online_request(self, func, *args):
rsp = await func(*args)
code = await self.state.check_log_state(func)
# print(rsp)
# 未登陆且未处理
if rsp == 3 and code:
self.printer_with_id([f'判定出现了登陆失败,且未处理'], True)
self.state.logout()
# login
await self.handle_login_status()
# await asyncio.sleep(10)
print(self.state.delay_requests)
self.printer_with_id([f'已经登陆了'], True)
self.state.login()
rsp = await func(*args)
# 未登陆,但已处理
elif not code:
self.printer_with_id([f'判定出现了登陆失败,已经处理'], True)
rsp = await func(*args)
return rsp
async def update(self, func, values):
status = self.check_status(func, values)
if not status:
return await getattr(self, func)(*values)
def go_to_bed(self):
self.state.go_to_bed()
def wake_up(self):
self.state.wake_up()
def fall_in_jail(self):
self.state.fall_in_jail()
self.printer_with_id([f'抽奖脚本检测{self.user_id}为小黑屋'], True)
def out_of_jail(self):
self.state.out_of_jail()
def print_state(self):
return self.state.print_state()
def check_status(self, func, values):
return self.state.check_status(func, values)