-
Notifications
You must be signed in to change notification settings - Fork 87
/
db.py
126 lines (79 loc) · 3.23 KB
/
db.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from __future__ import annotations
from typing import Any
from dao import BuyInfo, DnfHelperChronicleExchangeList, DnfHelperChronicleUserActivityTopInfo
from db_def import ConfigInterface, DBInterface
# ----------------- 数据定义 -----------------
class DemoDB(DBInterface):
def __init__(self):
super().__init__()
self.int_val = 1
self.bool_val = True
class FirstRunDB(DBInterface):
def __init__(self):
super().__init__()
def get_version(self) -> str:
# 2.0.0 修改字段update为_update,废弃原有数据
return "2.0.0"
class WelfareDB(DBInterface):
def __init__(self):
super().__init__()
self.share_code_list: list[str] = []
self.exchanged_dict: dict[str, bool] = {}
class DianzanDB(DBInterface):
def __init__(self):
super().__init__()
self.day_to_dianzan_count: dict[str, int] = {}
self.used_content_ids: list[str] = []
self.content_ids: list[str] = []
class CaptchaDB(DBInterface):
def __init__(self):
super().__init__()
self.offset_to_history_succes_count: dict[str, int] = {}
def increse_success_count(self, offset: int):
success_key = str(offset) # 因为json只支持str作为key,所以需要强转一下,使用时再转回int
if success_key not in self.offset_to_history_succes_count:
self.offset_to_history_succes_count[success_key] = 0
self.offset_to_history_succes_count[success_key] += 1
class LoginRetryDB(DBInterface):
def __init__(self):
super().__init__()
self.recommended_first_retry_timeout: float = 0.0
self.history_success_timeouts: list[float] = []
class CacheDB(DBInterface):
def __init__(self):
super().__init__()
self.cache: dict[str, CacheInfo] = {}
def dict_fields_to_fill(self) -> list[tuple[str, type[ConfigInterface]]]:
return [("cache", CacheInfo)]
class CacheInfo(DBInterface):
def __init__(self):
super().__init__()
self.value: Any = None
class FireCrackersDB(DBInterface):
def __init__(self):
super().__init__()
self.friend_qqs: list[str] = []
class UserBuyInfoDB(DBInterface):
def __init__(self):
super().__init__()
self.buy_info = BuyInfo()
class DnfHelperChronicleUserActivityTopInfoDB(DBInterface):
def __init__(self):
super().__init__()
self.account_name = ""
self.year_month_to_user_info: dict[str, DnfHelperChronicleUserActivityTopInfo] = {}
def dict_fields_to_fill(self) -> list[tuple[str, type[ConfigInterface]]]:
return [("year_month_to_user_info", DnfHelperChronicleUserActivityTopInfo)]
def get_last_month_user_info(self) -> DnfHelperChronicleUserActivityTopInfo:
from util import get_last_month
last_month = get_last_month()
if last_month not in self.year_month_to_user_info:
return DnfHelperChronicleUserActivityTopInfo()
return self.year_month_to_user_info[last_month]
class DnfHelperChronicleExchangeListDB(DBInterface):
def __init__(self):
super().__init__()
self.exchange_list = DnfHelperChronicleExchangeList()
if __name__ == "__main__":
print(DBInterface())
print(DemoDB())