Created
May 12, 2022 01:47
-
-
Save KenoLeon/cd365c40b47cc82e9101b02c12e5fb3f to your computer and use it in GitHub Desktop.
Parse Static JSON API respnse
This file contains hidden or 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
| # AccuEeather API call example 5 Day Forecast for | |
| # Mexico City Code: 242560 | |
| response = {'Headline': {'EffectiveDate': '2022-05-14T08:00:00-05:00', 'EffectiveEpochDate': 1652533200, 'Severity': 4, 'Text': 'Pleasant this weekend', 'Category': 'mild', 'EndDate': None, 'EndEpochDate': None, 'MobileLink': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?lang=en-us', 'Link': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?lang=en-us'}, 'DailyForecasts': [{'Date': '2022-05-11T07:00:00-05:00', 'EpochDate': 1652270400, 'Temperature': {'Minimum': {'Value': 54.0, 'Unit': 'F', 'UnitType': 18}, 'Maximum': {'Value': 79.0, 'Unit': 'F', 'UnitType': 18}}, 'Day': {'Icon': 3, 'IconPhrase': 'Partly sunny', 'HasPrecipitation': False}, 'Night': {'Icon': 33, 'IconPhrase': 'Clear', 'HasPrecipitation': False}, 'Sources': ['AccuWeather'], 'MobileLink': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?day=1&lang=en-us', 'Link': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?day=1&lang=en-us'}, {'Date': '2022-05-12T07:00:00-05:00', 'EpochDate': 1652356800, 'Temperature': {'Minimum': {'Value': 52.0, 'Unit': 'F', 'UnitType': 18}, 'Maximum': {'Value': 84.0, 'Unit': 'F', 'UnitType': 18}}, 'Day': {'Icon': 1, 'IconPhrase': 'Sunny', 'HasPrecipitation': False}, 'Night': {'Icon': 34, 'IconPhrase': 'Mostly clear', 'HasPrecipitation': False}, 'Sources': ['AccuWeather'], 'MobileLink': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?day=2&lang=en-us', 'Link': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?day=2&lang=en-us'}, {'Date': '2022-05-13T07:00:00-05:00', 'EpochDate': 1652443200, 'Temperature': {'Minimum': { | |
| 'Value': 54.0, 'Unit': 'F', 'UnitType': 18}, 'Maximum': {'Value': 85.0, 'Unit': 'F', 'UnitType': 18}}, 'Day': {'Icon': 4, 'IconPhrase': 'Intermittent clouds', 'HasPrecipitation': False}, 'Night': {'Icon': 35, 'IconPhrase': 'Partly cloudy', 'HasPrecipitation': False}, 'Sources': ['AccuWeather'], 'MobileLink': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?day=3&lang=en-us', 'Link': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?day=3&lang=en-us'}, {'Date': '2022-05-14T07:00:00-05:00', 'EpochDate': 1652529600, 'Temperature': {'Minimum': {'Value': 54.0, 'Unit': 'F', 'UnitType': 18}, 'Maximum': {'Value': 87.0, 'Unit': 'F', 'UnitType': 18}}, 'Day': {'Icon': 2, 'IconPhrase': 'Mostly sunny', 'HasPrecipitation': False}, 'Night': {'Icon': 35, 'IconPhrase': 'Partly cloudy', 'HasPrecipitation': False}, 'Sources': ['AccuWeather'], 'MobileLink': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?day=4&lang=en-us', 'Link': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?day=4&lang=en-us'}, {'Date': '2022-05-15T07:00:00-05:00', 'EpochDate': 1652616000, 'Temperature': {'Minimum': {'Value': 53.0, 'Unit': 'F', 'UnitType': 18}, 'Maximum': {'Value': 87.0, 'Unit': 'F', 'UnitType': 18}}, 'Day': {'Icon': 2, 'IconPhrase': 'Mostly sunny', 'HasPrecipitation': False}, 'Night': {'Icon': 35, 'IconPhrase': 'Partly cloudy', 'HasPrecipitation': False}, 'Sources': ['AccuWeather'], 'MobileLink': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?day=5&lang=en-us', 'Link': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?day=5&lang=en-us'}]} | |
| # pretty print response | |
| # import json | |
| # print(json.dumps(response, indent=4, sort_keys=True)) | |
| Dailyforecasts = response['DailyForecasts'] | |
| for forecast in Dailyforecasts: | |
| print(forecast['Date']) | |
| print(forecast['Temperature']['Minimum']['Value']) | |
| print(forecast['Temperature']['Maximum']['Value']) | |
| # >>> | |
| # 2022-05-11T07:00:00-05:00 | |
| # 54.0 | |
| # 79.0 | |
| # 2022-05-12T07:00:00-05:00 | |
| # 52.0 | |
| # 84.0 | |
| # 2022-05-13T07:00:00-05:00 | |
| # 54.0 | |
| # 85.0 | |
| # 2022-05-14T07:00:00-05:00 | |
| # 54.0 | |
| # 87.0 | |
| # 2022-05-15T07:00:00-05:00 | |
| # 53.0 | |
| # 87.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment