检索日期和温度-全球天气API

时间:2018-11-24 19:02:59

标签: django python-3.x api

我以为我知道如何做到这一点,但是我正在为一个类项目工作,而我无法获得返回值的api。我已经签入Postman,并且API工作正常。

*我的问题是如何从API返回日期和max_temp?这两个变量是date和max_temp,它们的当前格式不起作用。

我的代码:

w, h = 3, i
final_list = [[0 for x in range(w)] for y in range(h)]
while z < i:
    date = (json_data["data"][z]["weather"]["date"])
    max_temp = (json_data["data"][z]["weather"]["max_temp"])
    final_list[z][0] = date
    final_list[z][1] = max_temp
    final_list[z][2] = z
    z = z + 1
HttpResponse(final_list)

我玩过各种格式,试图弄清楚列表和字典。

"data": {
"request": {
  "type": "IATA",
  "query": "oma, Eppley Airfield, United States of America"
},
"weather": {
  "date": "2018-11-24",
  "astronomy": {
    "sunrise": "07:23 AM",
    "sunset": "04:58 PM",
    "moonrise": "06:35 PM",
    "moonset": "08:42 AM",
    "moon_phase": "Waning Gibbous",
    "moon_illumination": "97"
  },
  "maxtempC": "8",
  "maxtempF": "47",
  "mintempC": "-1",
  "mintempF": "31",
  "totalSnow_cm": "0.0",
  "sunHour": "8.7",
  "uvIndex": "2",
  "hourly": [
    {

感谢您的帮助。 布伦特

0 个答案:

没有答案