You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
|
|
|
|
r = requests.get("http://opendata.cwb.gov.tw/api/v1/rest/datastore/F-D0047-061?Authorization=CWB-6B764FB3-BD6E-4198-96C0-43FB4EBA1375&limit=10&offset=0&format=JSON&elementName=T&sort=time")
|
|
|
|
list_of_dicts = r.json()
|
|
|
|
list_of_dicts2 = list_of_dicts["records"]["locations"][0]
|
|
|
|
list_of_dicts3 = list_of_dicts2["location"]
|
|
|
|
# 形成列表 北投區為[0] 松山區[1] 士林區[2] 內湖區[3] 中山區[4] 中正區為[5] 信義區為[6] 大安區[7] 文山區[8] 南港區[9]
|
|
|
|
# for i in list_of_dicts3:
|
|
|
|
# print(i["locationName"])
|
|
|
|
print("請輸入地區:(數字)")
|
|
|
|
x = input("北投區為[0] 松山區[1] 士林區[2] 內湖區[3] 中山區[4] 中正區為[5] 信義區為[6] 大安區[7] 文山區[8] 南港區[9]:")
|
|
|
|
y = int(x)
|
|
|
|
# for i in list_of_dicts3:")
|
|
|
|
location_name = list_of_dicts3[y]
|
|
|
|
list_of_dicts5 = location_name["weatherElement"][0]
|
|
|
|
list_of_dicts6 = list_of_dicts5["time"]
|
|
|
|
# for i in list_of_dicts6:
|
|
|
|
# print(i["dataTime"])
|
|
|
|
# 此列表為每三個小時的時間
|
|
|
|
# for i in list_of_dicts6:
|
|
|
|
# print(i["elementValue"][0])
|
|
|
|
print(list_of_dicts3[y]["locationName"])
|
|
|
|
print(list_of_dicts6[0])
|