Skip to content

Instantly share code, notes, and snippets.

@aambrioso1
Created January 5, 2020 21:16
Show Gist options
  • Save aambrioso1/9037ee78a76d67665cf2eec4aef77a1e to your computer and use it in GitHub Desktop.
Save aambrioso1/9037ee78a76d67665cf2eec4aef77a1e to your computer and use it in GitHub Desktop.
noaa_json.py
import json, requests, sys
"""
Example of using the request package for json data from NOAA.
Here are Links to the documentation for these important libraries and the home of JSON.
https://docs.python.org/3/library/json.html
https://docs.python.org/3/library/sys.html
https://pypi.org/project/requests/
http://json.org/
Website with NOWA API information:
https://tidesandcurrents.noaa.gov/api/
"""
"""
Things to do
******++++¥+
(1) Incorporate time into the URL so that temp data goes back from current time.
(2) Make line graphs for temp/time for all stations.
"""
# Typical URL for the request.
# url = 'https://tidesandcurrents.noaa.gov/api/datagetter?begin_date=20130808 15:00&end_date=20130808 15:06&station=8454000&product=water_temperature&units=english&time_zone=gmt&application=ports_screen&format=json'
start = '20130808 15:00'
end = '20130808 15:06'
start2 = '20200104 14:00'
end2 = '20200104 15:00'
station1 = '8726520' # St Petersburg
station2 = '8726384' # Port Manatee
station3 = '8726607' # Old Port Tampa Bay
station4 = '8726667' # Mckay Bay Entrance
station5 = '8726724' # Clearwater Beach
zone1 = 'gmt'
zone2 = 'lst'
url = 'https://tidesandcurrents.noaa.gov/api/datagetter?begin_date={}&end_date={}&station={}&product=water_temperature&units=english&time_zone={}&application=ports_screen&format=json'.format(start2, end2, station2, zone2)
response = requests.get(url)
response.raise_for_status()
# Load JSON data into a Python variable.
data = json.loads(response.text)
# print(data)
print(data['metadata']['name'])
# Print weather descriptions.
d = data['data']
# print('Station data:\n', d)
print('*' * 35)
for item in d:
print('Time: {}: temp: {}'.format(item['t'], item['v']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment