yf_yzl hace 2 años
padre
commit
5534c5b65c
Se han modificado 1 ficheros con 16 adiciones y 13 borrados
  1. 16 13
      crond_script/crond_weather.py

+ 16 - 13
crond_script/crond_weather.py

@@ -77,6 +77,21 @@ def init_data():
     
 
 def main():
+
+    day_data = DayData.objects.all()
+    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}"
+        today_response = requests.get(today_url, timeout=5)
+        try:
+            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"cityid {day_obj.cityid}  error {e} {today_response.text}")
+        time.sleep(random.randint(1, 5))
+
     logging.warning("up server day ...")
     server_days = ServerDayData.objects.all()
     for server_day_obj in server_days:
@@ -93,19 +108,7 @@ def main():
         time.sleep(random.randint(1, 5))
     logging.warning("over server day ...")
 
-    day_data = DayData.objects.all()
-    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}"
-        today_response = requests.get(today_url, timeout=5)
-        try:
-            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"cityid {day_obj.cityid}  error {e} {today_response.text}")
-        time.sleep(random.randint(1, 5))
+