对只读情况做处理

This commit is contained in:
Womsxd 2022-04-26 16:15:47 +08:00
parent 148e7e6025
commit e9749386f5
No known key found for this signature in database
GPG Key ID: 0FE76418EE689B68
2 changed files with 26 additions and 13 deletions

View File

@ -75,6 +75,7 @@ def load_config():
def save_config():
global serverless
if not serverless:
log.info("云函数执行,无法保存")
return None
@ -83,16 +84,23 @@ def save_config():
data["mihoyobbs_Login_ticket"] = login_ticket
data["mihoyobbs_Stuid"] = stuid
data["mihoyobbs_Stoken"] = stoken
temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': '))
try:
f.seek(0)
f.truncate()
temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': '))
f.write(temp_text)
f.flush()
f.close()
except OSError:
serverless = True
log.info("Cookie保存失败")
exit(-1)
else:
log.info("Config保存完毕")
f.close()
def clear_cookies():
global serverless
if not serverless:
log.info("云函数执行,无法保存")
return None
@ -103,10 +111,15 @@ def clear_cookies():
data["mihoyobbs_Stuid"] = ""
data["mihoyobbs_Stoken"] = ""
data["mihoyobbs_Cookies"] = "CookieError"
temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': '))
try:
f.seek(0)
f.truncate()
temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': '))
f.write(temp_text)
f.flush()
f.close()
except OSError:
serverless = True
log.info("Cookie删除失败")
else:
log.info("Cookie删除完毕")
f.close()

View File

@ -1,12 +1,12 @@
import main
import push
import config
import main_multi
from error import CookieError
from config import serverless
def main_handler(event: dict, context: dict):
serverless = True
config.serverless = True
try:
status_code, push_message = main.main()
except CookieError:
@ -17,7 +17,7 @@ def main_handler(event: dict, context: dict):
def main_handler_mulit(event: dict, context: dict):
serverless = True
config.serverless = True
# 多用户需要传递True表示自动执行不需要手动进行确认
main_multi.main_multi(True)
print("云函数多用户测试支持!")