From 9edf4306a2127ce412454e0831a5c32993fb06d9 Mon Sep 17 00:00:00 2001 From: GamerNoTitle Date: Sun, 22 Nov 2020 09:14:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8D=95=E6=8D=89=E5=B9=B6=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF(=E5=BE=85=E6=B5=8B?= =?UTF-8?q?=E8=AF=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 27e8530..3f4e98d 100644 --- a/main.py +++ b/main.py @@ -6,20 +6,31 @@ import telepot tele_enable=False sign='https://n.cg.163.com/api/v2/sign-today' current='https://n.cg.163.com/api/v2/client-settings/@current' -with open('cookie.txt','r') as f: - cookie=f.read() - f.close +cookie='' +try: + with open('cookie.txt','r') as f: + cookie=f.read() + f.close +except FileNotFoundError as e: + print('[网易云游戏自动签到]无法读取Cookie,请检查是否正确设置Cookie!错误回显为:\n{}'.format(e)) + sys.exit() +except Exception as e: + print('[网易云游戏自动签到]无法读取Cookie,回显为\n{}'.format(e)) + sys.exit() -with open('teleid.txt','r') as f: - teleid=f.read() - f.close() +try: + with open('teleid.txt','r') as f: + teleid=f.read() + f.close() -with open('teletoken.txt','r') as f: - teletoken=f.read() - f.close - -if teletoken!='' and teleid!='': + with open('teletoken.txt','r') as f: + teletoken=f.read() + f.close tele_enable=True +except: + tele_enable=False + +if tele_enable: bot=telepot.Bot(teletoken) @@ -70,6 +81,9 @@ def send(id,message): bot.sendMessage(id, message, parse_mode=None, disable_web_page_preview=None, disable_notification=None, reply_to_message_id=None, reply_markup=None) if __name__ == "__main__": + if cookie=='': + print('[网易云游戏自动签到]未设置Cookie!正在退出……') + sys.exit() me=getme(current,getheader) if(me.status_code!=200): message='[网易云游戏自动签到]签到失败!请检查Cookie是否过期!或者附上报错信息到 https://github.com/GamerNoTitle/wyycg-autosignin/issues 发起issue'