Skip to content

Instantly share code, notes, and snippets.

@tom-henderson
Created February 22, 2018 05:12
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 tom-henderson/adaab27a43906261bd11db0be4e2be27 to your computer and use it in GitHub Desktop.
Save tom-henderson/adaab27a43906261bd11db0be4e2be27 to your computer and use it in GitHub Desktop.
import requests
url = "https://api-dot-translate-safeswim.appspot.com/v1/locations/4829360"
data = json.loads(requests.get(url))
days = [
'today',
'tomorrow',
'dayAfter'
]
periods = [
'morning',
'afternoon',
'evening',
'afterHours'
]
def quality_description(level):
level = float(level)
if (0 <= level < 140):
return "Good"
elif (140 <= level < 279):
return "Caution"
elif (level > 279 or level == -1):
return "Danger"
else:
return "Unknown"
for day in days:
for period in periods:
quality = data['forecast'][day][period]['waterQuality']['value']
print "{} - {}: {} {}".format(
day,
period,
quality,
quality_description(quality)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment