|
|
@@ -78,7 +78,7 @@ def init_data():
|
|
|
|
|
|
def main():
|
|
|
|
|
|
- day_data = DayData.objects.filter(id__gte=873)
|
|
|
+ day_data = DayData.objects.filter(id__gte=904)
|
|
|
for day_obj in day_data:
|
|
|
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}"
|
|
|
@@ -97,14 +97,15 @@ def main():
|
|
|
day_obj.save()
|
|
|
else:
|
|
|
logging.warning(f"cityid {day_obj.cityid} error_code {today_response.status_code}")
|
|
|
+ logging.warning(f"request fail again : {day_obj.cityid}")
|
|
|
+ today_response = requests.get(today_url, headers=headers, timeout=5)
|
|
|
+ if today_response.status_code == 200:
|
|
|
+ today_data = json.loads(today_response.text)
|
|
|
+ if "errcode" not in today_data.keys():
|
|
|
+ day_obj.content = str(today_data)
|
|
|
+ day_obj.save()
|
|
|
except Exception as e:
|
|
|
logging.warning(f"request fail again : {day_obj.cityid}")
|
|
|
- today_response = requests.get(today_url, headers=headers, timeout=5)
|
|
|
- if today_response.status_code == 200:
|
|
|
- today_data = json.loads(today_response.text)
|
|
|
- if "errcode" not in today_data.keys():
|
|
|
- day_obj.content = str(today_data)
|
|
|
- day_obj.save()
|
|
|
time.sleep(random.randint(1, 5))
|
|
|
|
|
|
logging.warning("up server day ...")
|