Update weather.py

This commit is contained in:
星光-k
2025-01-19 01:19:21 +08:00
committed by GitHub
parent 5436cba3d0
commit ab6abaf2e3

View File

@@ -41,7 +41,7 @@ def get_area_id(city_name):
logging.error("从city.js接收到的数据为空")
except (requests.RequestException, json.JSONDecodeError) as e:
logging.error("检索或解析城市数据时发生错误: %s", e)
time.sleep(5) # 重试前等待5秒
time.sleep(180) # 重试前等待
def get_current_city():
"""获取当前城市名称,无限重试直到成功"""
@@ -57,7 +57,7 @@ def get_current_city():
logging.error("获取当前城市失败: %s", data['message'])
except (requests.RequestException, json.JSONDecodeError) as e:
logging.error("检索或解析当前城市时出现错误: %s", e)
time.sleep(5) # 重试前等待5秒
time.sleep(180) # 重试前等待
# 注意:无限重试可能会在特定情况下导致程序无法终止,请确保在实际使用中考虑适当的退出条件或限制重试次数。
def getWeath(city='101060101'):
@@ -87,7 +87,7 @@ def getWeath(city='101060101'):
try:
getWeath() # 天气获取函数开始运行
except IOError as e:
except OSError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("检测到键盘中断,正在退出")
@@ -96,4 +96,4 @@ except Exception as e:
exit()
# 脚本正常结束后的清理操作
exit()
exit()