Skip to content

Instantly share code, notes, and snippets.

@aaronlelevier
Created August 15, 2017 14:37
Show Gist options
  • Select an option

  • Save aaronlelevier/258c4f3dae2ada124d1ce9ec31fd53fa to your computer and use it in GitHub Desktop.

Select an option

Save aaronlelevier/258c4f3dae2ada124d1ce9ec31fd53fa to your computer and use it in GitHub Desktop.
Sample code for requesting La Jolla, CA tide predictions from www.tidesandcurrents.noaa.gov
import requests
import json
url = "https://tidesandcurrents.noaa.gov/api/datagetter?begin_date=20170816&end_date=20170816&station=9410230&datum=MLLW&product=predictions&units=english&time_zone=lst&format=json"
r = requests.get(url, headers=headers)
content = r.content.decode('utf8')
if 'wrong' not in content.lower():
try:
data = json.loads(content)
except Exception:
data = content
else:
data = r.__dict__
data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment