Created
October 14, 2019 20:42
-
-
Save hkjn/4796d74a7638e9e97df4121e02e72408 to your computer and use it in GitHub Desktop.
Small python script to demo fetching info from a web API
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
import json | |
import urllib.request | |
LAT = 39.7456 | |
LON = -97.0892 | |
URL = 'https://api.weather.gov/points/{},{}'.format(LAT, LON) | |
print('Getting weather info for point {}, {}'.format(LAT, LON)) | |
response = urllib.request.urlopen(URL).read() | |
json_response = json.loads(response) | |
properties = json_response['properties']['relativeLocation']['properties'] | |
forecast_url = json_response['properties']['forecast'] | |
print('Weather prognosis for {}, {} can be found at:'.format(properties['city'], properties['state'])) | |
print(forecast_url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment