-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ce4ca5
commit 6fd6f2f
Showing
13 changed files
with
117 additions
and
702 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
qweather.py | ||
~~~~~~~~~ | ||
使用和风天气数据查询天气 | ||
""" | ||
|
||
import requests | ||
import json | ||
|
||
KEY = '882e721338b4441dbf1b7e514029aaa8' # API key(私钥) | ||
UID = "" # 用户ID, @todo: 当前并没有使用这个值,签名验证方式将使用到这个值 | ||
|
||
# LOCATION = 'beijing' # 所查询的位置,可以使用城市拼音、v3 ID、经纬度等 | ||
API_loc_id = 'https://geoapi.qweather.com/v2/city/lookup?' # 城市id查询 | ||
API = 'https://devapi.qweather.com/v7/weather/3d?' # API URL,可替换为其他 URL | ||
# UNIT = 'c' # 单位 | ||
# LANGUAGE = 'zh-Hans' # 查询结果的返回语言 | ||
|
||
def fetch_location_id(location): | ||
result = requests.get(API_loc_id, params={ | ||
'key': KEY, | ||
'location': location, | ||
}) | ||
return result.json() | ||
|
||
def fetch_weather(location_id): | ||
result = requests.get(API, params={ | ||
'key': KEY, | ||
'location': location_id, | ||
}) | ||
return result.json() | ||
|
||
def get_weather_by_day(location, day=1): | ||
location_id = fetch_location_id(location)["location"][0]["id"] | ||
result = fetch_weather(location_id) | ||
normal_result = { | ||
"location": location, | ||
"fxDate": result["daily"][day]["fxDate"], | ||
"tempMax": result["daily"][day]["tempMax"], | ||
"tempMin": result["daily"][day]["tempMin"], | ||
"textDay": result["daily"][day]["textDay"], | ||
"textNight": result["daily"][day]["textNight"], | ||
"humidity": result["daily"][day]["humidity"] | ||
} | ||
|
||
return normal_result | ||
|
||
if __name__ == "__main__": | ||
print(get_weather_by_day('上海', 1)) | ||
print(json.dumps(get_weather_by_day('上海', 1), ensure_ascii=False)) |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Oops, something went wrong.