yf_yzl 2 anni fa
parent
commit
9b80f0d715
2 ha cambiato i file con 36 aggiunte e 38 eliminazioni
  1. 10 0
      apps/apply_weather.py
  2. 26 38
      crond_script/crond_weather.py

+ 10 - 0
apps/apply_weather.py

@@ -39,6 +39,7 @@ province_dict = {
 }
 
 
+
 logging.basicConfig(level=logging.DEBUG, filename='/data/logs/app.log', filemode='w',
                     format='%(asctime)s - %(levelname)s - %(message)s')
 
@@ -55,6 +56,15 @@ class GetWeather(APIView):
             day_type = data.get("day_type")
             conn = sqlite3.connect(db)
             cursor = conn.cursor()
+            username = data.get("username")
+            password = data.get("password")
+            sql = """
+            select * from user where username = ? and password = ?
+            """
+            cursor.execute(sql, (username, password,))
+            user = cursor.fetchone()
+            if not user:
+                return Response({"msg":"认证失败", "code": 400})
             table = "day_data" if day_type == "1" else "serven_day_data"
             table = "day_data" if day_type == "1" else "server_day_data"
             sql = f"select content from {table} where province = '{province}' and city ='{city}' and district ='{district}'"

+ 26 - 38
crond_script/crond_weather.py

@@ -122,48 +122,36 @@ def main():
                     city = temp 
                     district = ""
                 else:
-                    if pid == 620500000000:
-                        print(pid, '=================================')
-                        cursor1.execute('select city from district where id = ?', (pid,))
-                        te = cursor1.fetchone()
-                        city = te[0] 
-                        district = temp
-                        print(district, city, "-------%%%%%%%%%%%-------")
-                    else:
-                        print(pid)
-                        cursor1.execute('select city from district where id = ?', (pid,))
-                        te = cursor1.fetchone()
-                        city = te[0] 
-                        district = temp
-                        print(district, city, "--------------")
+                    print(pid)
+                    cursor1.execute('select city from district where id = ?', (pid,))
+                    te = cursor1.fetchone()
+                    city = te[0] 
+                    district = temp
+                    print(district, city, "--------------")
                 province_id = (str(row[0]))[:2]
                 province = province_dict.get(province_id)
                 
-                if district == '唐河县' or city == "郑州市" or city == "市辖区":
-                    today_url = f"https://v0.yiketianqi.com/api?unescape=1&version=v62&appid={app_id}&appsecret={app_secret}&adcode={id}"
-                    today_response = requests.get(today_url)
-                    today_data = json.loads(today_response.text)
-                    if "errcode" not in today_data.keys():
-                        today_sql = """
-                            INSERT OR REPLACE INTO `day_data` (`id`,`province`, `city`, `district`, content) VALUES (?, ?, ?, ?, ?)
-                        """
-                        cursor1.execute(today_sql, (i, province, city, district,str(today_data)))
-                        print(city, district, province, "---------------------")
-                    if hour in special_time:
-                        server_day_url = f"https://v0.yiketianqi.com/api?unescape=1&version=v91&appid={app_id}&appsecret={app_secret}&adcode={id}"
-                        server_day_response = requests.get(server_day_url)
-                        server_day_data = json.loads(server_day_response.text)
-                        if "errcode" not in server_day_data.keys():
-                            server_sql = f"""
-                                INSERT OR REPLACE INTO `server_day_data` (`id`,`province`, `city`, `district`, `content`) VALUES (?, ?, ?, ?, ?)
-                            """
-                            cursor1.execute(server_sql, (i, province, city, district,str(server_day_data),))
-                            print(city, district, province, "+++++++++++++++++++++")
-                    conn1.commit()
+                # if district == '唐河县' or city == "郑州市" or city == "市辖区":
+                today_url = f"https://v0.yiketianqi.com/api?unescape=1&version=v62&appid={app_id}&appsecret={app_secret}&adcode={id}"
+                today_response = requests.get(today_url)
+                today_data = json.loads(today_response.text)
+                if "errcode" not in today_data.keys():
+                    today_sql = """
+                        INSERT OR REPLACE INTO `day_data` (`id`,`province`, `city`, `district`, content) VALUES (?, ?, ?, ?, ?)
+                    """
+                    cursor1.execute(today_sql, (i, province, city, district,str(today_data)))
+                    print(city, district, province, "---------------------")
+                server_day_url = f"https://v0.yiketianqi.com/api?unescape=1&version=v91&appid={app_id}&appsecret={app_secret}&adcode={id}"
+                server_day_response = requests.get(server_day_url)
+                server_day_data = json.loads(server_day_response.text)
+                if "errcode" not in server_day_data.keys():
+                    server_sql = f"""
+                        INSERT OR REPLACE INTO `server_day_data` (`id`,`province`, `city`, `district`, `content`) VALUES (?, ?, ?, ?, ?)
+                    """
+                    cursor1.execute(server_sql, (i, province, city, district,str(server_day_data),))
+                    print(city, district, province, "+++++++++++++++++++++")
+                conn1.commit()
             conn1.close()
-            print("start sleep...")
-            time.sleep(3600)
-            
 
 
 if __name__ == "__main__":