Home > Enterprise >  For loop for JSON data from API
For loop for JSON data from API

Time:06-17

I'm trying to pull out the Average, Min and Max Temperature as well as UV index for each 'date' (06/16 - 06/18) from Weather API data. The idea is to run the loop for the three days of data from the API call and get data for 06/16/2022, 06/17/2022,and 06/18/2022. I can't get the loop to work and I think I'm having a hard time deciphering the structure of the JSON file. There are dicts in there.

I'd also like to pull the hourly data from the 'hour' object of the JSON response. For a Data science project I'd like to pull the hourly data and save to a database that can be used in Python or exported to Excel for basic cleanup or visualization.

Here is my code:

response = requests.get(url).json()
#for loop 
for days in response:
   date = response['forecast']['forecastday'][0]['date']
   avgtemp = response['forecast']['forecastday'][0]['day']['avgtemp_f']
   mintemp = response['forecast']['forecastday'][0]['day']['mintemp_f']
   maxtemp = response['forecast']['forecastday'][0]['day']['maxtemp_f']
   uv = response['forecast']['forecastday'][0]['day']['uv']

print(date)
print(avgtemp)
print(mintemp)
print(maxtemp)
print(uv)

without specifying [0] this error appears:

TypeError                                 Traceback (most recent call last)
<ipython-input-9-2ac82a55a57b> in <module>()
      6 for days in response:
      7   date = response['forecast']['forecastday'][0]['date']
----> 8   avgtemp = response['forecast']['forecastday']['day']['avgtemp_f']
      9   mintemp = response['forecast']['forecastday'][0]['day']['mintemp_f']
     10   maxtemp = response['forecast']['forecastday'][0]['day']['maxtemp_f']

TypeError: list indices must be integers or slices, not str

Here is the JSON response from the API call:

{'astro': {'moon_illumination': '78',
  'moon_phase': 'Waxing Gibbous',
  'moonrise': '10:21 PM',
  'moonset': '07:27 AM',
  'sunrise': '05:18 AM',
  'sunset': '07:33 PM'},
  'date': '2022-06-16',
  'date_epoch': 1655337600,
  'day': {'avghumidity': 8.0,
   'avgtemp_c': 34.3,
   'avgtemp_f': 93.8,
   'avgvis_km': 10.0,


'avgvis_miles': 6.0,
  'condition': {'code': 1000,
   'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png',
   'text': 'Sunny'},
  'daily_chance_of_rain': 0,
  'daily_chance_of_snow': 0,
  'daily_will_it_rain': 0,
  'daily_will_it_snow': 0,
  'maxtemp_c': 43.2,


'maxtemp_f': 109.8,
  'maxwind_kph': 33.8,
  'maxwind_mph': 21.0,
  'mintemp_c': 26.1,
  'mintemp_f': 79.0,
  'totalprecip_in': 0.0,
  'totalprecip_mm': 0.0,
  'uv': 11.0},
 'hour': [{'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 0,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/night/113.png',
    'text': 'Clear'},
   'dewpoint_c': -9.1,
   'dewpoint_f': 15.6,
   'feelslike_c': 27.1,
   'feelslike_f': 80.8,
   'gust_kph': 11.2,
   'gust_mph': 6.9,
   'heatindex_c': 27.1,
   'heatindex_f': 80.8,
   'humidity': 8,
   'is_day': 0,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.77,
   'pressure_mb': 1008.0,
   'temp_c': 29.3,
   'temp_f': 84.7,
   'time': '2022-06-16 00:00',
   'time_epoch': 1655362800,
   'uv': 1.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 280,
   'wind_dir': 'W',
   'wind_kph': 5.4,
   'wind_mph': 3.4,
   'windchill_c': 29.3,
   'windchill_f': 84.7},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 0,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/night/113.png',
    'text': 'Clear'},
   'dewpoint_c': -8.4,
   'dewpoint_f': 16.9,
   'feelslike_c': 26.5,
   'feelslike_f': 79.7,
   'gust_kph': 9.0,
   'gust_mph': 5.6,
   'heatindex_c': 26.5,
   'heatindex_f': 79.7,
   'humidity': 8,
   'is_day': 0,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.78,
   'pressure_mb': 1009.0,
   'temp_c': 28.6,
   'temp_f': 83.5,
   'time': '2022-06-16 01:00',
   'time_epoch': 1655366400,
   'uv': 1.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 243,
   'wind_dir': 'WSW',
   'wind_kph': 4.3,
   'wind_mph': 2.7,
   'windchill_c': 28.6,
   'windchill_f': 83.5},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 0,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/night/113.png',
    'text': 'Clear'},
   'dewpoint_c': -8.0,
   'dewpoint_f': 17.6,
   'feelslike_c': 25.9,
   'feelslike_f': 78.6,
   'gust_kph': 9.0,
   'gust_mph': 5.6,
   'heatindex_c': 25.9,
   'heatindex_f': 78.6,
   'humidity': 9,
   'is_day': 0,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.79,
   'pressure_mb': 1009.0,
   'temp_c': 27.9,
   'temp_f': 82.2,
   'time': '2022-06-16 02:00',
   'time_epoch': 1655370000,
   'uv': 1.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 219,
   'wind_dir': 'SW',
   'wind_kph': 4.3,
   'wind_mph': 2.7,
   'windchill_c': 27.9,
   'windchill_f': 82.2},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 0,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/night/113.png',
    'text': 'Clear'},
   'dewpoint_c': -8.0,
   'dewpoint_f': 17.6,
   'feelslike_c': 25.8,
   'feelslike_f': 78.4,
   'gust_kph': 11.2,
   'gust_mph': 6.9,
   'heatindex_c': 25.8,
   'heatindex_f': 78.4,
   'humidity': 9,
   'is_day': 0,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.77,
   'pressure_mb': 1008.0,
   'temp_c': 27.7,
   'temp_f': 81.9,
   'time': '2022-06-16 03:00',
   'time_epoch': 1655373600,
   'uv': 1.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 200,
   'wind_dir': 'SSW',
   'wind_kph': 5.4,
   'wind_mph': 3.4,
   'windchill_c': 27.7,
   'windchill_f': 81.9},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 0,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/night/113.png',
    'text': 'Clear'},
   'dewpoint_c': -7.7,
   'dewpoint_f': 18.1,
   'feelslike_c': 25.4,
   'feelslike_f': 77.7,
   'gust_kph': 10.4,
   'gust_mph': 6.5,
   'heatindex_c': 25.4,
   'heatindex_f': 77.7,
   'humidity': 10,
   'is_day': 0,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.77,
   'pressure_mb': 1008.0,
   'temp_c': 27.2,
   'temp_f': 81.0,
   'time': '2022-06-16 04:00',
   'time_epoch': 1655377200,
   'uv': 1.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 187,
   'wind_dir': 'S',
   'wind_kph': 5.0,
   'wind_mph': 3.1,
   'windchill_c': 27.2,
   'windchill_f': 81.0},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 0,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/night/113.png',
    'text': 'Clear'},
   'dewpoint_c': -7.1,
   'dewpoint_f': 19.2,
   'feelslike_c': 24.9,
   'feelslike_f': 76.8,
   'gust_kph': 9.7,
   'gust_mph': 6.0,
   'heatindex_c': 24.9,
   'heatindex_f': 76.8,
   'humidity': 10,
   'is_day': 0,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.77,
   'pressure_mb': 1008.0,
   'temp_c': 26.6,
   'temp_f': 79.9,
   'time': '2022-06-16 05:00',
   'time_epoch': 1655380800,
   'uv': 1.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 164,
   'wind_dir': 'SSE',
   'wind_kph': 4.7,
   'wind_mph': 2.9,
   'windchill_c': 26.6,
   'windchill_f': 79.9},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 0,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png',
    'text': 'Sunny'},
   'dewpoint_c': -6.9,
   'dewpoint_f': 19.6,
   'feelslike_c': 24.5,
   'feelslike_f': 76.1,
   'gust_kph': 6.8,
   'gust_mph': 4.3,
   'heatindex_c': 24.5,
   'heatindex_f': 76.1,
   'humidity': 11,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.77,
   'pressure_mb': 1008.0,
   'temp_c': 26.1,
   'temp_f': 79.0,
   'time': '2022-06-16 06:00',
   'time_epoch': 1655384400,
   'uv': 7.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 128,
   'wind_dir': 'SE',
   'wind_kph': 3.2,
   'wind_mph': 2.0,
   'windchill_c': 26.1,
   'windchill_f': 79.0},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 0,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png',
    'text': 'Sunny'},
   'dewpoint_c': -5.7,
   'dewpoint_f': 21.7,
   'feelslike_c': 25.4,
   'feelslike_f': 77.7,
   'gust_kph': 7.6,
   'gust_mph': 4.7,
   'heatindex_c': 25.4,
   'heatindex_f': 77.7,
   'humidity': 11,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.79,
   'pressure_mb': 1009.0,
   'temp_c': 27.3,
   'temp_f': 81.1,
   'time': '2022-06-16 07:00',
   'time_epoch': 1655388000,
   'uv': 7.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 146,
   'wind_dir': 'SSE',
   'wind_kph': 3.6,
   'wind_mph': 2.2,
   'windchill_c': 27.3,
   'windchill_f': 81.1},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 0,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png',
    'text': 'Sunny'},
   'dewpoint_c': -7.7,
   'dewpoint_f': 18.1,
   'feelslike_c': 27.8,
   'feelslike_f': 82.0,
   'gust_kph': 6.5,
   'gust_mph': 4.0,
   'heatindex_c': 27.8,
   'heatindex_f': 82.0,
   'humidity': 8,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.8,
   'pressure_mb': 1009.0,
   'temp_c': 30.0,
   'temp_f': 86.0,
   'time': '2022-06-16 08:00',
   'time_epoch': 1655391600,
   'uv': 8.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 179,
   'wind_dir': 'S',
   'wind_kph': 4.7,
   'wind_mph': 2.9,
   'windchill_c': 30.0,
   'windchill_f': 86.0},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 0,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png',
    'text': 'Sunny'},
   'dewpoint_c': -9.7,
   'dewpoint_f': 14.5,
   'feelslike_c': 29.6,
   'feelslike_f': 85.3,
   'gust_kph': 5.4,
   'gust_mph': 3.4,
   'heatindex_c': 29.6,
   'heatindex_f': 85.3,
   'humidity': 6,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.8,
   'pressure_mb': 1009.0,
   'temp_c': 31.8,
   'temp_f': 89.2,
   'time': '2022-06-16 09:00',
   'time_epoch': 1655395200,
   'uv': 8.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 168,
   'wind_dir': 'SSE',
   'wind_kph': 4.3,
   'wind_mph': 2.7,
   'windchill_c': 31.8,
   'windchill_f': 89.2},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 0,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png',
    'text': 'Sunny'},
   'dewpoint_c': -9.4,
   'dewpoint_f': 15.1,
   'feelslike_c': 31.3,
   'feelslike_f': 88.3,
   'gust_kph': 2.9,
   'gust_mph': 1.8,
   'heatindex_c': 31.3,
   'heatindex_f': 88.3,
   'humidity': 6,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.79,
   'pressure_mb': 1009.0,
   'temp_c': 33.4,
   'temp_f': 92.1,
   'time': '2022-06-16 10:00',
   'time_epoch': 1655398800,
   'uv': 8.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 131,
   'wind_dir': 'SE',
   'wind_kph': 2.5,
   'wind_mph': 1.6,
   'windchill_c': 33.4,
   'windchill_f': 92.1},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 0,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png',
    'text': 'Sunny'},
   'dewpoint_c': -7.3,
   'dewpoint_f': 18.9,
   'feelslike_c': 36.9,
   'feelslike_f': 98.4,
   'gust_kph': 2.2,
   'gust_mph': 1.3,
   'heatindex_c': 36.9,
   'heatindex_f': 98.4,
   'humidity': 5,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.78,
   'pressure_mb': 1008.0,
   'temp_c': 37.9,
   'temp_f': 100.2,
   'time': '2022-06-16 11:00',
   'time_epoch': 1655402400,
   'uv': 9.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 68,
   'wind_dir': 'ENE',
   'wind_kph': 1.8,
   'wind_mph': 1.1,
   'windchill_c': 37.9,
   'windchill_f': 100.2},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 2,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png',
    'text': 'Sunny'},
   'dewpoint_c': -7.3,
   'dewpoint_f': 18.9,
   'feelslike_c': 39.2,
   'feelslike_f': 102.6,
   'gust_kph': 3.2,
   'gust_mph': 2.0,
   'heatindex_c': 39.2,
   'heatindex_f': 102.6,
   'humidity': 5,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.76,
   'pressure_mb': 1008.0,
   'temp_c': 39.5,
   'temp_f': 103.1,
   'time': '2022-06-16 12:00',
   'time_epoch': 1655406000,
   'uv': 9.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 4,
   'wind_dir': 'N',
   'wind_kph': 2.9,
   'wind_mph': 1.8,
   'windchill_c': 39.5,
   'windchill_f': 103.1},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 4,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png',
    'text': 'Sunny'},
   'dewpoint_c': -6.9,
   'dewpoint_f': 19.6,
   'feelslike_c': 41.4,
   'feelslike_f': 106.5,
   'gust_kph': 3.6,
   'gust_mph': 2.2,
   'heatindex_c': 41.4,
   'heatindex_f': 106.5,
   'humidity': 5,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.74,
   'pressure_mb': 1007.0,
   'temp_c': 41.0,
   'temp_f': 105.8,
   'time': '2022-06-16 13:00',
   'time_epoch': 1655409600,
   'uv': 10.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 338,
   'wind_dir': 'NNW',
   'wind_kph': 3.2,
   'wind_mph': 2.0,
   'windchill_c': 41.0,
   'windchill_f': 105.8},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 7,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png',
    'text': 'Sunny'},
   'dewpoint_c': -6.1,
   'dewpoint_f': 21.0,
   'feelslike_c': 43.3,
   'feelslike_f': 109.9,
   'gust_kph': 5.0,
   'gust_mph': 3.1,
   'heatindex_c': 43.3,
   'heatindex_f': 109.9,
   'humidity': 5,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.7,
   'pressure_mb': 1006.0,
   'temp_c': 42.2,
   'temp_f': 108.0,
   'time': '2022-06-16 14:00',
   'time_epoch': 1655413200,
   'uv': 10.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 317,
   'wind_dir': 'NW',
   'wind_kph': 4.3,
   'wind_mph': 2.7,
   'windchill_c': 42.2,
   'windchill_f': 108.0},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 11,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png',
    'text': 'Sunny'},
   'dewpoint_c': -4.9,
   'dewpoint_f': 23.2,
   'feelslike_c': 44.9,
   'feelslike_f': 112.8,
   'gust_kph': 9.4,
   'gust_mph': 5.8,
   'heatindex_c': 44.9,
   'heatindex_f': 112.8,
   'humidity': 5,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.67,
   'pressure_mb': 1005.0,
   'temp_c': 43.2,
   'temp_f': 109.8,
   'time': '2022-06-16 15:00',
   'time_epoch': 1655416800,
   'uv': 10.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 309,
   'wind_dir': 'NW',
   'wind_kph': 8.3,
   'wind_mph': 5.1,
   'windchill_c': 43.2,
   'windchill_f': 109.8},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 18,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png',
    'text': 'Sunny'},
   'dewpoint_c': -5.1,
   'dewpoint_f': 22.8,
   'feelslike_c': 42.2,
   'feelslike_f': 108.0,
   'gust_kph': 13.0,
   'gust_mph': 8.1,
   'heatindex_c': 42.2,
   'heatindex_f': 108.0,
   'humidity': 5,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.63,
   'pressure_mb': 1003.0,
   'temp_c': 41.5,
   'temp_f': 106.7,
   'time': '2022-06-16 16:00',
   'time_epoch': 1655420400,
   'uv': 10.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 302,
   'wind_dir': 'WNW',
   'wind_kph': 11.2,
   'wind_mph': 6.9,
   'windchill_c': 41.5,
   'windchill_f': 106.7},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 27,
   'condition': {'code': 1003,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/116.png',
    'text': 'Partly cloudy'},
   'dewpoint_c': -4.2,
   'dewpoint_f': 24.4,
   'feelslike_c': 42.3,
   'feelslike_f': 108.1,
   'gust_kph': 13.7,
   'gust_mph': 8.5,
   'heatindex_c': 42.3,
   'heatindex_f': 108.1,
   'humidity': 6,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.59,
   'pressure_mb': 1002.0,
   'temp_c': 41.6,
   'temp_f': 106.9,
   'time': '2022-06-16 17:00',
   'time_epoch': 1655424000,
   'uv': 10.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 289,
   'wind_dir': 'WNW',
   'wind_kph': 11.9,
   'wind_mph': 7.4,
   'windchill_c': 41.6,
   'windchill_f': 106.9},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 32,
   'condition': {'code': 1003,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/116.png',
    'text': 'Partly cloudy'},
   'dewpoint_c': -3.6,
   'dewpoint_f': 25.5,
   'feelslike_c': 41.9,
   'feelslike_f': 107.4,
   'gust_kph': 10.8,
   'gust_mph': 6.7,
   'heatindex_c': 41.9,
   'heatindex_f': 107.4,
   'humidity': 6,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.57,
   'pressure_mb': 1001.0,
   'temp_c': 41.3,
   'temp_f': 106.3,
   'time': '2022-06-16 18:00',
   'time_epoch': 1655427600,
   'uv': 10.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 291,
   'wind_dir': 'WNW',
   'wind_kph': 9.4,
   'wind_mph': 5.8,
   'windchill_c': 41.3,
   'windchill_f': 106.3},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 44,
   'condition': {'code': 1003,
    'icon': '//cdn.weatherapi.com/weather/64x64/day/116.png',
    'text': 'Partly cloudy'},
   'dewpoint_c': -2.4,
   'dewpoint_f': 27.7,
   'feelslike_c': 41.1,
   'feelslike_f': 106.0,
   'gust_kph': 5.0,
   'gust_mph': 3.1,
   'heatindex_c': 41.1,
   'heatindex_f': 106.0,
   'humidity': 7,
   'is_day': 1,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.56,
   'pressure_mb': 1001.0,
   'temp_c': 40.8,
   'temp_f': 105.4,
   'time': '2022-06-16 19:00',
   'time_epoch': 1655431200,
   'uv': 10.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 301,
   'wind_dir': 'WNW',
   'wind_kph': 4.3,
   'wind_mph': 2.7,
   'windchill_c': 40.8,
   'windchill_f': 105.4},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 45,
   'condition': {'code': 1003,
    'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png',
    'text': 'Partly cloudy'},
   'dewpoint_c': -0.9,
   'dewpoint_f': 30.4,
   'feelslike_c': 38.5,
   'feelslike_f': 101.3,
   'gust_kph': 21.6,
   'gust_mph': 13.4,
   'heatindex_c': 38.5,
   'heatindex_f': 101.3,
   'humidity': 8,
   'is_day': 0,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.59,
   'pressure_mb': 1002.0,
   'temp_c': 39.0,
   'temp_f': 102.2,
   'time': '2022-06-16 20:00',
   'time_epoch': 1655434800,
   'uv': 1.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 278,
   'wind_dir': 'W',
   'wind_kph': 16.2,
   'wind_mph': 10.1,
   'windchill_c': 39.0,
   'windchill_f': 102.2},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 25,
   'condition': {'code': 1000,
    'icon': '//cdn.weatherapi.com/weather/64x64/night/113.png',
    'text': 'Clear'},
   'dewpoint_c': -1.1,
   'dewpoint_f': 30.0,
   'feelslike_c': 33.7,
   'feelslike_f': 92.7,
   'gust_kph': 46.1,
   'gust_mph': 28.6,
   'heatindex_c': 33.7,
   'heatindex_f': 92.7,
   'humidity': 10,
   'is_day': 0,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.65,
   'pressure_mb': 1004.0,
   'temp_c': 35.4,
   'temp_f': 95.7,
   'time': '2022-06-16 21:00',
   'time_epoch': 1655438400,
   'uv': 1.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 263,
   'wind_dir': 'W',
   'wind_kph': 33.8,
   'wind_mph': 21.0,
   'windchill_c': 35.4,
   'windchill_f': 95.7},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 31,
   'condition': {'code': 1003,
    'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png',
    'text': 'Partly cloudy'},
   'dewpoint_c': -0.7,
   'dewpoint_f': 30.7,
   'feelslike_c': 31.0,
   'feelslike_f': 87.8,
   'gust_kph': 24.5,
   'gust_mph': 15.2,
   'heatindex_c': 31.0,
   'heatindex_f': 87.8,
   'humidity': 11,
   'is_day': 0,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.72,
   'pressure_mb': 1006.0,
   'temp_c': 33.1,
   'temp_f': 91.6,
   'time': '2022-06-16 22:00',
   'time_epoch': 1655442000,
   'uv': 1.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 243,
   'wind_dir': 'WSW',
   'wind_kph': 15.8,
   'wind_mph': 9.8,
   'windchill_c': 33.1,
   'windchill_f': 91.6},
  {'chance_of_rain': 0,
   'chance_of_snow': 0,
   'cloud': 30,
   'condition': {'code': 1003,
    'icon': '//cdn.weatherapi.com/weather/64x64/night/116.png',
    'text': 'Partly cloudy'},
   'dewpoint_c': -0.4,
   'dewpoint_f': 31.3,
   'feelslike_c': 29.3,
   'feelslike_f': 84.7,
   'gust_kph': 9.7,
   'gust_mph': 6.0,
   'heatindex_c': 29.3,
   'heatindex_f': 84.7,
   'humidity': 13,
   'is_day': 0,
   'precip_in': 0.0,
   'precip_mm': 0.0,
   'pressure_in': 29.73,
   'pressure_mb': 1007.0,
   'temp_c': 31.5,
   'temp_f': 88.7,
   'time': '2022-06-16 23:00',
   'time_epoch': 1655445600,
   'uv': 1.0,
   'vis_km': 10.0,
   'vis_miles': 6.0,
   'will_it_rain': 0,
   'will_it_snow': 0,
   'wind_degree': 307,
   'wind_dir': 'NW',
   'wind_kph': 5.4,
   'wind_mph': 3.4,
   'windchill_c': 31.5,
   'windchill_f': 88.7}]}

CodePudding user response:

Maybe you are trying to access things incorrectly. See if this helps:

import json
data={
   "astro":{
      "moon_illumination":"78",
      "moon_phase":"Waxing Gibbous",
      "moonrise":"10:21 PM",
      "moonset":"07:27 AM",
      "sunrise":"05:18 AM",
      "sunset":"07:33 PM"
   },
   "date":"2022-06-16",
   "date_epoch":1655337600,
   "day":{
      "avghumidity":8.0,
      "avgtemp_c":34.3,
      "avgtemp_f":93.8,
      "avgvis_km":10.0,
      "avgvis_miles":6.0,
      "condition":{
         "code":1000,
         "icon":"//cdn.weatherapi.com/weather/64x64/day/113.png",
         "text":"Sunny"
      },
      "daily_chance_of_rain":0,
      "daily_chance_of_snow":0,
      "daily_will_it_rain":0,
      "daily_will_it_snow":0,
      "maxtemp_c":43.2,
      "maxtemp_f":109.8,
      "maxwind_kph":33.8,
      "maxwind_mph":21.0,
      "mintemp_c":26.1,
      "mintemp_f":79.0,
      "totalprecip_in":0.0,
      "totalprecip_mm":0.0,
      "uv":11.0
   },
   "hour":[
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":0,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/night/113.png",
            "text":"Clear"
         },
         "dewpoint_c":-9.1,
         "dewpoint_f":15.6,
         "feelslike_c":27.1,
         "feelslike_f":80.8,
         "gust_kph":11.2,
         "gust_mph":6.9,
         "heatindex_c":27.1,
         "heatindex_f":80.8,
         "humidity":8,
         "is_day":0,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.77,
         "pressure_mb":1008.0,
         "temp_c":29.3,
         "temp_f":84.7,
         "time":"2022-06-16 00:00",
         "time_epoch":1655362800,
         "uv":1.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":280,
         "wind_dir":"W",
         "wind_kph":5.4,
         "wind_mph":3.4,
         "windchill_c":29.3,
         "windchill_f":84.7
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":0,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/night/113.png",
            "text":"Clear"
         },
         "dewpoint_c":-8.4,
         "dewpoint_f":16.9,
         "feelslike_c":26.5,
         "feelslike_f":79.7,
         "gust_kph":9.0,
         "gust_mph":5.6,
         "heatindex_c":26.5,
         "heatindex_f":79.7,
         "humidity":8,
         "is_day":0,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.78,
         "pressure_mb":1009.0,
         "temp_c":28.6,
         "temp_f":83.5,
         "time":"2022-06-16 01:00",
         "time_epoch":1655366400,
         "uv":1.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":243,
         "wind_dir":"WSW",
         "wind_kph":4.3,
         "wind_mph":2.7,
         "windchill_c":28.6,
         "windchill_f":83.5
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":0,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/night/113.png",
            "text":"Clear"
         },
         "dewpoint_c":-8.0,
         "dewpoint_f":17.6,
         "feelslike_c":25.9,
         "feelslike_f":78.6,
         "gust_kph":9.0,
         "gust_mph":5.6,
         "heatindex_c":25.9,
         "heatindex_f":78.6,
         "humidity":9,
         "is_day":0,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.79,
         "pressure_mb":1009.0,
         "temp_c":27.9,
         "temp_f":82.2,
         "time":"2022-06-16 02:00",
         "time_epoch":1655370000,
         "uv":1.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":219,
         "wind_dir":"SW",
         "wind_kph":4.3,
         "wind_mph":2.7,
         "windchill_c":27.9,
         "windchill_f":82.2
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":0,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/night/113.png",
            "text":"Clear"
         },
         "dewpoint_c":-8.0,
         "dewpoint_f":17.6,
         "feelslike_c":25.8,
         "feelslike_f":78.4,
         "gust_kph":11.2,
         "gust_mph":6.9,
         "heatindex_c":25.8,
         "heatindex_f":78.4,
         "humidity":9,
         "is_day":0,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.77,
         "pressure_mb":1008.0,
         "temp_c":27.7,
         "temp_f":81.9,
         "time":"2022-06-16 03:00",
         "time_epoch":1655373600,
         "uv":1.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":200,
         "wind_dir":"SSW",
         "wind_kph":5.4,
         "wind_mph":3.4,
         "windchill_c":27.7,
         "windchill_f":81.9
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":0,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/night/113.png",
            "text":"Clear"
         },
         "dewpoint_c":-7.7,
         "dewpoint_f":18.1,
         "feelslike_c":25.4,
         "feelslike_f":77.7,
         "gust_kph":10.4,
         "gust_mph":6.5,
         "heatindex_c":25.4,
         "heatindex_f":77.7,
         "humidity":10,
         "is_day":0,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.77,
         "pressure_mb":1008.0,
         "temp_c":27.2,
         "temp_f":81.0,
         "time":"2022-06-16 04:00",
         "time_epoch":1655377200,
         "uv":1.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":187,
         "wind_dir":"S",
         "wind_kph":5.0,
         "wind_mph":3.1,
         "windchill_c":27.2,
         "windchill_f":81.0
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":0,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/night/113.png",
            "text":"Clear"
         },
         "dewpoint_c":-7.1,
         "dewpoint_f":19.2,
         "feelslike_c":24.9,
         "feelslike_f":76.8,
         "gust_kph":9.7,
         "gust_mph":6.0,
         "heatindex_c":24.9,
         "heatindex_f":76.8,
         "humidity":10,
         "is_day":0,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.77,
         "pressure_mb":1008.0,
         "temp_c":26.6,
         "temp_f":79.9,
         "time":"2022-06-16 05:00",
         "time_epoch":1655380800,
         "uv":1.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":164,
         "wind_dir":"SSE",
         "wind_kph":4.7,
         "wind_mph":2.9,
         "windchill_c":26.6,
         "windchill_f":79.9
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":0,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/113.png",
            "text":"Sunny"
         },
         "dewpoint_c":-6.9,
         "dewpoint_f":19.6,
         "feelslike_c":24.5,
         "feelslike_f":76.1,
         "gust_kph":6.8,
         "gust_mph":4.3,
         "heatindex_c":24.5,
         "heatindex_f":76.1,
         "humidity":11,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.77,
         "pressure_mb":1008.0,
         "temp_c":26.1,
         "temp_f":79.0,
         "time":"2022-06-16 06:00",
         "time_epoch":1655384400,
         "uv":7.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":128,
         "wind_dir":"SE",
         "wind_kph":3.2,
         "wind_mph":2.0,
         "windchill_c":26.1,
         "windchill_f":79.0
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":0,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/113.png",
            "text":"Sunny"
         },
         "dewpoint_c":-5.7,
         "dewpoint_f":21.7,
         "feelslike_c":25.4,
         "feelslike_f":77.7,
         "gust_kph":7.6,
         "gust_mph":4.7,
         "heatindex_c":25.4,
         "heatindex_f":77.7,
         "humidity":11,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.79,
         "pressure_mb":1009.0,
         "temp_c":27.3,
         "temp_f":81.1,
         "time":"2022-06-16 07:00",
         "time_epoch":1655388000,
         "uv":7.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":146,
         "wind_dir":"SSE",
         "wind_kph":3.6,
         "wind_mph":2.2,
         "windchill_c":27.3,
         "windchill_f":81.1
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":0,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/113.png",
            "text":"Sunny"
         },
         "dewpoint_c":-7.7,
         "dewpoint_f":18.1,
         "feelslike_c":27.8,
         "feelslike_f":82.0,
         "gust_kph":6.5,
         "gust_mph":4.0,
         "heatindex_c":27.8,
         "heatindex_f":82.0,
         "humidity":8,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.8,
         "pressure_mb":1009.0,
         "temp_c":30.0,
         "temp_f":86.0,
         "time":"2022-06-16 08:00",
         "time_epoch":1655391600,
         "uv":8.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":179,
         "wind_dir":"S",
         "wind_kph":4.7,
         "wind_mph":2.9,
         "windchill_c":30.0,
         "windchill_f":86.0
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":0,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/113.png",
            "text":"Sunny"
         },
         "dewpoint_c":-9.7,
         "dewpoint_f":14.5,
         "feelslike_c":29.6,
         "feelslike_f":85.3,
         "gust_kph":5.4,
         "gust_mph":3.4,
         "heatindex_c":29.6,
         "heatindex_f":85.3,
         "humidity":6,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.8,
         "pressure_mb":1009.0,
         "temp_c":31.8,
         "temp_f":89.2,
         "time":"2022-06-16 09:00",
         "time_epoch":1655395200,
         "uv":8.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":168,
         "wind_dir":"SSE",
         "wind_kph":4.3,
         "wind_mph":2.7,
         "windchill_c":31.8,
         "windchill_f":89.2
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":0,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/113.png",
            "text":"Sunny"
         },
         "dewpoint_c":-9.4,
         "dewpoint_f":15.1,
         "feelslike_c":31.3,
         "feelslike_f":88.3,
         "gust_kph":2.9,
         "gust_mph":1.8,
         "heatindex_c":31.3,
         "heatindex_f":88.3,
         "humidity":6,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.79,
         "pressure_mb":1009.0,
         "temp_c":33.4,
         "temp_f":92.1,
         "time":"2022-06-16 10:00",
         "time_epoch":1655398800,
         "uv":8.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":131,
         "wind_dir":"SE",
         "wind_kph":2.5,
         "wind_mph":1.6,
         "windchill_c":33.4,
         "windchill_f":92.1
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":0,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/113.png",
            "text":"Sunny"
         },
         "dewpoint_c":-7.3,
         "dewpoint_f":18.9,
         "feelslike_c":36.9,
         "feelslike_f":98.4,
         "gust_kph":2.2,
         "gust_mph":1.3,
         "heatindex_c":36.9,
         "heatindex_f":98.4,
         "humidity":5,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.78,
         "pressure_mb":1008.0,
         "temp_c":37.9,
         "temp_f":100.2,
         "time":"2022-06-16 11:00",
         "time_epoch":1655402400,
         "uv":9.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":68,
         "wind_dir":"ENE",
         "wind_kph":1.8,
         "wind_mph":1.1,
         "windchill_c":37.9,
         "windchill_f":100.2
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":2,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/113.png",
            "text":"Sunny"
         },
         "dewpoint_c":-7.3,
         "dewpoint_f":18.9,
         "feelslike_c":39.2,
         "feelslike_f":102.6,
         "gust_kph":3.2,
         "gust_mph":2.0,
         "heatindex_c":39.2,
         "heatindex_f":102.6,
         "humidity":5,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.76,
         "pressure_mb":1008.0,
         "temp_c":39.5,
         "temp_f":103.1,
         "time":"2022-06-16 12:00",
         "time_epoch":1655406000,
         "uv":9.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":4,
         "wind_dir":"N",
         "wind_kph":2.9,
         "wind_mph":1.8,
         "windchill_c":39.5,
         "windchill_f":103.1
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":4,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/113.png",
            "text":"Sunny"
         },
         "dewpoint_c":-6.9,
         "dewpoint_f":19.6,
         "feelslike_c":41.4,
         "feelslike_f":106.5,
         "gust_kph":3.6,
         "gust_mph":2.2,
         "heatindex_c":41.4,
         "heatindex_f":106.5,
         "humidity":5,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.74,
         "pressure_mb":1007.0,
         "temp_c":41.0,
         "temp_f":105.8,
         "time":"2022-06-16 13:00",
         "time_epoch":1655409600,
         "uv":10.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":338,
         "wind_dir":"NNW",
         "wind_kph":3.2,
         "wind_mph":2.0,
         "windchill_c":41.0,
         "windchill_f":105.8
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":7,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/113.png",
            "text":"Sunny"
         },
         "dewpoint_c":-6.1,
         "dewpoint_f":21.0,
         "feelslike_c":43.3,
         "feelslike_f":109.9,
         "gust_kph":5.0,
         "gust_mph":3.1,
         "heatindex_c":43.3,
         "heatindex_f":109.9,
         "humidity":5,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.7,
         "pressure_mb":1006.0,
         "temp_c":42.2,
         "temp_f":108.0,
         "time":"2022-06-16 14:00",
         "time_epoch":1655413200,
         "uv":10.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":317,
         "wind_dir":"NW",
         "wind_kph":4.3,
         "wind_mph":2.7,
         "windchill_c":42.2,
         "windchill_f":108.0
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":11,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/113.png",
            "text":"Sunny"
         },
         "dewpoint_c":-4.9,
         "dewpoint_f":23.2,
         "feelslike_c":44.9,
         "feelslike_f":112.8,
         "gust_kph":9.4,
         "gust_mph":5.8,
         "heatindex_c":44.9,
         "heatindex_f":112.8,
         "humidity":5,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.67,
         "pressure_mb":1005.0,
         "temp_c":43.2,
         "temp_f":109.8,
         "time":"2022-06-16 15:00",
         "time_epoch":1655416800,
         "uv":10.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":309,
         "wind_dir":"NW",
         "wind_kph":8.3,
         "wind_mph":5.1,
         "windchill_c":43.2,
         "windchill_f":109.8
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":18,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/113.png",
            "text":"Sunny"
         },
         "dewpoint_c":-5.1,
         "dewpoint_f":22.8,
         "feelslike_c":42.2,
         "feelslike_f":108.0,
         "gust_kph":13.0,
         "gust_mph":8.1,
         "heatindex_c":42.2,
         "heatindex_f":108.0,
         "humidity":5,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.63,
         "pressure_mb":1003.0,
         "temp_c":41.5,
         "temp_f":106.7,
         "time":"2022-06-16 16:00",
         "time_epoch":1655420400,
         "uv":10.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":302,
         "wind_dir":"WNW",
         "wind_kph":11.2,
         "wind_mph":6.9,
         "windchill_c":41.5,
         "windchill_f":106.7
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":27,
         "condition":{
            "code":1003,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/116.png",
            "text":"Partly cloudy"
         },
         "dewpoint_c":-4.2,
         "dewpoint_f":24.4,
         "feelslike_c":42.3,
         "feelslike_f":108.1,
         "gust_kph":13.7,
         "gust_mph":8.5,
         "heatindex_c":42.3,
         "heatindex_f":108.1,
         "humidity":6,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.59,
         "pressure_mb":1002.0,
         "temp_c":41.6,
         "temp_f":106.9,
         "time":"2022-06-16 17:00",
         "time_epoch":1655424000,
         "uv":10.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":289,
         "wind_dir":"WNW",
         "wind_kph":11.9,
         "wind_mph":7.4,
         "windchill_c":41.6,
         "windchill_f":106.9
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":32,
         "condition":{
            "code":1003,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/116.png",
            "text":"Partly cloudy"
         },
         "dewpoint_c":-3.6,
         "dewpoint_f":25.5,
         "feelslike_c":41.9,
         "feelslike_f":107.4,
         "gust_kph":10.8,
         "gust_mph":6.7,
         "heatindex_c":41.9,
         "heatindex_f":107.4,
         "humidity":6,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.57,
         "pressure_mb":1001.0,
         "temp_c":41.3,
         "temp_f":106.3,
         "time":"2022-06-16 18:00",
         "time_epoch":1655427600,
         "uv":10.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":291,
         "wind_dir":"WNW",
         "wind_kph":9.4,
         "wind_mph":5.8,
         "windchill_c":41.3,
         "windchill_f":106.3
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":44,
         "condition":{
            "code":1003,
            "icon":"//cdn.weatherapi.com/weather/64x64/day/116.png",
            "text":"Partly cloudy"
         },
         "dewpoint_c":-2.4,
         "dewpoint_f":27.7,
         "feelslike_c":41.1,
         "feelslike_f":106.0,
         "gust_kph":5.0,
         "gust_mph":3.1,
         "heatindex_c":41.1,
         "heatindex_f":106.0,
         "humidity":7,
         "is_day":1,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.56,
         "pressure_mb":1001.0,
         "temp_c":40.8,
         "temp_f":105.4,
         "time":"2022-06-16 19:00",
         "time_epoch":1655431200,
         "uv":10.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":301,
         "wind_dir":"WNW",
         "wind_kph":4.3,
         "wind_mph":2.7,
         "windchill_c":40.8,
         "windchill_f":105.4
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":45,
         "condition":{
            "code":1003,
            "icon":"//cdn.weatherapi.com/weather/64x64/night/116.png",
            "text":"Partly cloudy"
         },
         "dewpoint_c":-0.9,
         "dewpoint_f":30.4,
         "feelslike_c":38.5,
         "feelslike_f":101.3,
         "gust_kph":21.6,
         "gust_mph":13.4,
         "heatindex_c":38.5,
         "heatindex_f":101.3,
         "humidity":8,
         "is_day":0,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.59,
         "pressure_mb":1002.0,
         "temp_c":39.0,
         "temp_f":102.2,
         "time":"2022-06-16 20:00",
         "time_epoch":1655434800,
         "uv":1.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":278,
         "wind_dir":"W",
         "wind_kph":16.2,
         "wind_mph":10.1,
         "windchill_c":39.0,
         "windchill_f":102.2
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":25,
         "condition":{
            "code":1000,
            "icon":"//cdn.weatherapi.com/weather/64x64/night/113.png",
            "text":"Clear"
         },
         "dewpoint_c":-1.1,
         "dewpoint_f":30.0,
         "feelslike_c":33.7,
         "feelslike_f":92.7,
         "gust_kph":46.1,
         "gust_mph":28.6,
         "heatindex_c":33.7,
         "heatindex_f":92.7,
         "humidity":10,
         "is_day":0,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.65,
         "pressure_mb":1004.0,
         "temp_c":35.4,
         "temp_f":95.7,
         "time":"2022-06-16 21:00",
         "time_epoch":1655438400,
         "uv":1.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":263,
         "wind_dir":"W",
         "wind_kph":33.8,
         "wind_mph":21.0,
         "windchill_c":35.4,
         "windchill_f":95.7
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":31,
         "condition":{
            "code":1003,
            "icon":"//cdn.weatherapi.com/weather/64x64/night/116.png",
            "text":"Partly cloudy"
         },
         "dewpoint_c":-0.7,
         "dewpoint_f":30.7,
         "feelslike_c":31.0,
         "feelslike_f":87.8,
         "gust_kph":24.5,
         "gust_mph":15.2,
         "heatindex_c":31.0,
         "heatindex_f":87.8,
         "humidity":11,
         "is_day":0,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.72,
         "pressure_mb":1006.0,
         "temp_c":33.1,
         "temp_f":91.6,
         "time":"2022-06-16 22:00",
         "time_epoch":1655442000,
         "uv":1.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":243,
         "wind_dir":"WSW",
         "wind_kph":15.8,
         "wind_mph":9.8,
         "windchill_c":33.1,
         "windchill_f":91.6
      },
      {
         "chance_of_rain":0,
         "chance_of_snow":0,
         "cloud":30,
         "condition":{
            "code":1003,
            "icon":"//cdn.weatherapi.com/weather/64x64/night/116.png",
            "text":"Partly cloudy"
         },
         "dewpoint_c":-0.4,
         "dewpoint_f":31.3,
         "feelslike_c":29.3,
         "feelslike_f":84.7,
         "gust_kph":9.7,
         "gust_mph":6.0,
         "heatindex_c":29.3,
         "heatindex_f":84.7,
         "humidity":13,
         "is_day":0,
         "precip_in":0.0,
         "precip_mm":0.0,
         "pressure_in":29.73,
         "pressure_mb":1007.0,
         "temp_c":31.5,
         "temp_f":88.7,
         "time":"2022-06-16 23:00",
         "time_epoch":1655445600,
         "uv":1.0,
         "vis_km":10.0,
         "vis_miles":6.0,
         "will_it_rain":0,
         "will_it_snow":0,
         "wind_degree":307,
         "wind_dir":"NW",
         "wind_kph":5.4,
         "wind_mph":3.4,
         "windchill_c":31.5,
         "windchill_f":88.7
      }
   ]
}
original_json=json.dumps(data) # original_json is what your api returns.
response=json.loads(original_json)

date = response['date']
avgtemp = response['day']['avgtemp_f']
mintemp = response['day']['mintemp_f']
maxtemp = response['day']['maxtemp_f']
uv = response['day']['uv']

print(str(date))
print(avgtemp)
print(mintemp)
print(maxtemp)
print(uv)

CodePudding user response:

After trying to infer the higher level structure of the response you're getting, I think the following would do what you want:

for day in response['forecast']['forecastday']:
    date = day['date']
    avgtemp = day['day']['avgtemp_f']
    mintemp = day['day']['mintemp_f']
    maxtemp = day['day']['maxtemp_f']
    uv = day['day']['uv']
    print(date)
    print(avgtemp)
    print(mintemp)
    print(maxtemp)
    print(uv)
    print()

  • Related