|
|
@@ -145,28 +145,30 @@ def main():
|
|
|
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, "---------------------")
|
|
|
- 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():
|
|
|
- logging.warning(f"{province, city, district} server day weather success")
|
|
|
- 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()
|
|
|
+ try:
|
|
|
+ # 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():
|
|
|
+ logging.warning(f"{province, city, district} server day weather success")
|
|
|
+ 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()
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
conn1.close()
|
|
|
|
|
|
|