|
|
@@ -83,9 +83,10 @@ def main():
|
|
|
'Accept-Encoding': 'gzip, deflate, br',
|
|
|
'Connection': 'keep-alive',
|
|
|
}
|
|
|
- day_data = DayData.objects.filter(id__gte=1062)
|
|
|
+ day_data = DayData.objects.filter(id__gte=2526)
|
|
|
today_error = 0
|
|
|
for day_obj in day_data:
|
|
|
+ time_out = False
|
|
|
logging.warning(day_obj.cityid)
|
|
|
today_url = f"http://v0.yiketianqi.com/api?unescape=1&version=v62&appid=69334222&appsecret=2ME6U58N&cityid={day_obj.cityid}"
|
|
|
today_response = requests.get(today_url, headers=headers, timeout=5)
|
|
|
@@ -108,15 +109,22 @@ def main():
|
|
|
else:
|
|
|
logging.warning(f"cityid {day_obj.cityid} error_code {today_response.status_code} again request fail")
|
|
|
logging.error(f"error {today_error}")
|
|
|
+ today_error += 1
|
|
|
+ time_out = True
|
|
|
except Exception as e:
|
|
|
logging.warning(f"request fail again : {day_obj.cityid} {e.args}")
|
|
|
- time.sleep(2)
|
|
|
- today_error += 1
|
|
|
+ if time_out:
|
|
|
+ time.sleep(5)
|
|
|
+ else:
|
|
|
+ time.sleep(2)
|
|
|
+
|
|
|
+
|
|
|
|
|
|
server_error = 0
|
|
|
logging.warning("up server day ...")
|
|
|
server_days = ServerDayData.objects.all()
|
|
|
for server_day_obj in server_days:
|
|
|
+ time_out_k = False
|
|
|
logging.warning(server_day_obj.cityid)
|
|
|
server_day_url = f"http://v0.yiketianqi.com/api?unescape=1&version=v91&appid=69334222&appsecret=2ME6U58N&cityid={server_day_obj.cityid}&ext=hours,aqi,life"
|
|
|
server_day_response = requests.get(server_day_url, headers=headers, timeout=5)
|
|
|
@@ -139,10 +147,15 @@ def main():
|
|
|
else:
|
|
|
logging.warning(f"cityid {day_obj.cityid} error_code {server_day_response.status_code} again request afil")
|
|
|
logging.error(f"error {server_error}")
|
|
|
+ server_error += 1
|
|
|
+ time_out_k = True
|
|
|
except Exception as e:
|
|
|
logging.warning(f"request fail again : {server_day_obj.cityid} {e.args}")
|
|
|
- time.sleep(2)
|
|
|
- server_error += 1
|
|
|
+ if time_out_k:
|
|
|
+ time.sleep(5)
|
|
|
+ else:
|
|
|
+ time.sleep(2)
|
|
|
+
|
|
|
|
|
|
|
|
|
"""
|