Created
February 22, 2018 05:12
-
-
Save tom-henderson/adaab27a43906261bd11db0be4e2be27 to your computer and use it in GitHub Desktop.
This file contains 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 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