Skip to content

Commit

Permalink
修复某些情况下的编码错误,fix #44
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonVanke committed May 31, 2021
1 parent c2612d7 commit fb94476
Show file tree
Hide file tree
Showing 2 changed files with 264 additions and 278 deletions.
15 changes: 7 additions & 8 deletions main.py
Expand Up @@ -14,10 +14,8 @@

@atexit.register
def _end():
if sys.exc_info()[0] is not None:
to_log("ERROR", "出现不可解决的错误", str(traceback.format_exc()))
else:
print(to_log("INFO", "执行结束\n"))
end_time = time.time()
print(to_log("INFO", "执行结束", "执行耗时{:.3f}s".format(end_time - start_time)))


def get_shopid():
Expand All @@ -33,7 +31,7 @@ def get_shopid():

if os.path.exists(get_file_path("shopid.yaml")):
try:
res = yaml.safe_load(open(get_file_path("shopid.yaml"), "r"))
res = yaml.safe_load(open(get_file_path("shopid.yaml"), "r", encoding="utf-8"))
except:
os.remove(get_file_path("shopid.yaml"))
print(to_log("ERROR", "shopid.yaml损坏", "已经删除损坏文件,请重新打开"))
Expand All @@ -44,7 +42,7 @@ def get_shopid():
'%Y-%m-%d')).days > 0:
print(to_log("INFO", "已更新 shopid"))
res = yaml.safe_load(net_res.text)
open(get_file_path("shopid.yaml"), "w").write(net_res.text)
open(get_file_path("shopid.yaml"), "w", encoding="utf-8").write(net_res.text)
except:
pass
print(to_log("INFO", "shopid更新时间", str(res['update_time'])))
Expand Down Expand Up @@ -249,16 +247,17 @@ def main():
time.sleep(0.5)
else:
print(to_log("ERROR", "cookie失效", _[-15:]))
print("\r 账号:{}, 共尝试{}个店铺,共获得{}京豆和{}元红包".format(username, process[0], process[1], process[2]), end="")
print(to_log("INFO", "账号{}".format(username), "共尝试{}个店铺,共获得{}京豆和{}元红包\n".format(process[0], process[1], process[2])))


if __name__ == '__main__':
start_time = time.time()
# 忽略警告
requests.packages.urllib3.disable_warnings()
if not os.path.exists(get_file_path("config.yaml")):
print(to_log("ERROR", "未找到配置`config.yaml`", "请查看 https://github.com/AntonVanke/JDBrandMember"))
sys.exit()
CONFIG = yaml.safe_load(open(get_file_path("config.yaml"), "r"))
CONFIG = yaml.safe_load(open(get_file_path("config.yaml"), "r", encoding="utf-8"))

process = [0, 0, 0]
# 获取 shopid 列表
Expand Down

0 comments on commit fb94476

Please sign in to comment.