-
Notifications
You must be signed in to change notification settings - Fork 28
/
Constant.py
163 lines (133 loc) · 5.28 KB
/
Constant.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# -*- coding: utf-8 -*-
import os
import json
import time
import logging
import win32api
import win32con
VERSION = "1.7.1.0"
BUILD_VERSION = 3
RES = {2: '油', 3: '弹', 4: '钢', 9: '铝', 10141: "航母核心", 10241: '战列核心', 10341: '巡洋核心', 10441: '驱逐核心',
10541: '潜艇核心', 141: '快速建造', 241: '建造蓝图', 541: '快速修理', 741: '装备蓝图', 66641: '损管'}
HEADER = {'Accept-Encoding': 'identity',
'Connection': 'Keep-Alive',
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 5.1.1; mi max Build/LMY48Z)'}
UPDATE_URL = "http://update.protector.moe/pc/version.json"
DOWNLOAD_URL = "https://github.com/ProtectorMoe/pc-protector-moe/releases/latest"
class G:
def __init__(self):
self.repair_time_limit = 0
self.all_log = 0
g = G()
class InitData:
def __init__(self):
self.init_out_data = False
self.init_version = None
self.init_data = dict()
self.ship_cid = dict()
self.ship_cid_wu = dict()
self.error_code = dict()
self.error_code_1 = dict()
self.handbook_id = dict()
self.new_init_version = None
self.ship_equipmnt = {}
self.res_url = ""
def read_init(self):
if not os.path.exists('data'):
os.mkdir('data')
if os.path.exists('data/init.json'):
with open('data/init.json', 'r') as f:
data = f.read()
self.init_data = json.loads(data)
#对比数据版本默认设置低版本
self.init_version = '20180927142352'
if "DataVersion" in self.init_data:
self.init_version = self.init_data["DataVersion"]
if "res_url" in self.init_data:
self.res_url = self.init_data["res_url"]
# 领导船只cid数据
for each_ship in self.init_data['shipCard']:
self.ship_cid[each_ship['cid']] = each_ship
# 普通船只cid数据
for each_ship in self.init_data['shipCardWu']:
self.ship_cid_wu[each_ship['cid']] = each_ship
# 错误代码
self.error_code_1 = self.init_data['errorCode']
for code, message in self.error_code_1.items():
self.error_code[int(code)] = message
# 图鉴代号
for each_ship in self.init_data['shipCard']:
if 'shipIndex' in each_ship:
self.handbook_id[each_ship['cid']] = each_ship['shipIndex']
# 装备属性
for equipment in self.init_data['shipEquipmnt']:
self.ship_equipmnt[equipment["cid"]] = equipment
class Logger:
def __init__(self, clevel=logging.DEBUG, flevel=logging.DEBUG):
self.windows = None
times = time.strftime("%m-%d-%H-%M-%S", time.localtime())
path = 'log/' + times + '.log'
self.path = path
if not os.path.exists('log'):
os.mkdir('log')
with open(path, 'w') as f:
f.write('')
self.logger = logging.getLogger('Main')
self.logger.setLevel(logging.DEBUG)
fmt = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s', '%Y-%m-%d %H:%M:%S')
# 设置CMD日志
sh = logging.StreamHandler()
sh.setFormatter(fmt)
sh.setLevel(clevel)
# 设置文件日志
fh = logging.FileHandler(path)
fh.setFormatter(fmt)
fh.setLevel(flevel)
self.logger.addHandler(sh)
self.logger.addHandler(fh)
def debug(self, *kwargs):
arg = [str(x) for x in kwargs]
self.logger.debug(" ".join(arg))
def info(self, *kwargs):
arg = [str(x) for x in kwargs]
self.logger.info(" ".join(arg))
def war(self, *kwargs):
arg = [str(x) for x in kwargs]
self.logger.warning(" ".join(arg))
def error(self, *kwargs):
arg = [str(x) for x in kwargs]
self.logger.error(" ".join(arg))
def cri(self, *kwargs):
arg = [str(x) for x in kwargs]
self.logger.critical(" ".join(arg))
def d(self, *kwargs):
arg = [str(x) for x in kwargs]
self.logger.debug(" ".join(arg))
def i(self, *kwargs):
arg = [str(x) for x in kwargs]
self.logger.info(" ".join(arg))
def w(self, *kwargs):
arg = [str(x) for x in kwargs]
self.logger.warning(" ".join(arg))
def e(self, *kwargs):
arg = [str(x) for x in kwargs]
self.logger.error(" ".join(arg))
def c(self, *kwargs):
arg = [str(x) for x in kwargs]
self.logger.critical(" ".join(arg))
@staticmethod
def get_desktop():
key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', 0,
win32con.KEY_READ)
return win32api.RegQueryValueEx(key, 'Desktop')[0]
def get_log(self):
try:
with open(self.path, 'r') as f:
with open(self.get_desktop() + "/护萌宝·Re{}.log".format(
time.strftime("%m-%d-%H-%M-%S", time.localtime())), 'w') as f2:
f2.write(f.read())
except Exception as e:
log.e("导出日志错误", e)
log = Logger(logging.DEBUG, logging.DEBUG)
init_data = InitData()