Skip to content

Instantly share code, notes, and snippets.

@hkjn
Created October 14, 2019 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkjn/4796d74a7638e9e97df4121e02e72408 to your computer and use it in GitHub Desktop.
Save hkjn/4796d74a7638e9e97df4121e02e72408 to your computer and use it in GitHub Desktop.
Small python script to demo fetching info from a web API
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