You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
1.1 KiB

11 months ago
11 months ago
  1. import requests
  2. import json
  3. 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")
  4. list_of_dicts = r.json()
  5. list_of_dicts2 = list_of_dicts["records"]["locations"][0]
  6. list_of_dicts3 = list_of_dicts2["location"]
  7. # 形成列表 北投區為[0] 松山區[1] 士林區[2] 內湖區[3] 中山區[4] 中正區為[5] 信義區為[6] 大安區[7] 文山區[8] 南港區[9]
  8. # for i in list_of_dicts3:
  9. # print(i["locationName"])
  10. print("請輸入地區:(數字)")
  11. x = input("北投區為[0] 松山區[1] 士林區[2] 內湖區[3] 中山區[4] 中正區為[5] 信義區為[6] 大安區[7] 文山區[8] 南港區[9]:")
  12. y = int(x)
  13. # for i in list_of_dicts3:")
  14. location_name = list_of_dicts3[y]
  15. list_of_dicts5 = location_name["weatherElement"][0]
  16. list_of_dicts6 = list_of_dicts5["time"]
  17. # for i in list_of_dicts6:
  18. # print(i["dataTime"])
  19. # 此列表為每三個小時的時間
  20. # for i in list_of_dicts6:
  21. # print(i["elementValue"][0])
  22. print(list_of_dicts3[y]["locationName"])
  23. print(list_of_dicts6[0])