- 改短间隔时间,并在消息之间使用长轮询

This commit is contained in:
yshtcn 2023-09-21 21:39:33 +08:00
parent 1c1d167cdd
commit 120089f301

View File

@ -83,8 +83,8 @@ except FileNotFoundError:
def get_updates(offset=None): def get_updates(offset=None):
try: try:
url = URL + "getUpdates" url = URL + "getUpdates"
params = {'offset': offset} params = {'offset': offset, 'timeout': 25}
r = requests.get(url, params=params, proxies=proxies) r = requests.get(url, params=params, proxies=proxies,timeout=30)
return r.json() return r.json()
except Exception as e: except Exception as e:
print(f"Error getting updates: {e}") print(f"Error getting updates: {e}")
@ -223,18 +223,18 @@ def main():
with open('blacklist.json', 'w') as f: with open('blacklist.json', 'w') as f:
json.dump(blacklist, f) json.dump(blacklist, f)
print("process message queue...") print("Process message queue...")
process_message_queue() process_message_queue()
else: else:
print(f"{URL} Received updates: {updates}") print(f"{URL} Received updates: {updates}")
print("Error or no updates; retrying in 30 seconds...") print("Error or no updates; retrying in 5 seconds...")
time.sleep(30) # 等待5秒再重试 time.sleep(5) # 等待5秒再重试
print("process message queue...") print("Process message queue...")
process_message_queue() process_message_queue()
# 每30s检查一次 # 每30s检查一次
print("waiting 30s...") print("Nexttime in 5 seconds...")
time.sleep(30) time.sleep(5)
# 运行主函数 # 运行主函数
if __name__ == '__main__': if __name__ == '__main__':