Created
July 28, 2022 17:51
-
-
Save ibuys/5bbd51b10bf7dab26fa379d09b02b18d 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
#!/usr/bin/env python3 | |
# coding=utf-8 | |
import json | |
import ssl | |
from urllib.request import urlopen | |
response = urlopen( | |
"https://api.forecast.io/forecast/{key}/{coordinates}", | |
context=ssl._create_unverified_context(), | |
).read() | |
data = json.loads(response) | |
summary = data["currently"]["summary"] | |
temperature = data["currently"]["temperature"] | |
icon = data["currently"]["icon"] | |
def iconEmoji(icon): | |
if icon == "clear-day": | |
return "☀️" | |
if icon == "clear-night": | |
return "🌕" | |
if icon == "rain": | |
return "🌧" | |
if icon == "snow": | |
return "❄️" | |
if icon == "sleet": | |
return "🌨" | |
if icon == "wind": | |
return "🌬" | |
if icon == "fog": | |
return "🌫" | |
if icon == "cloudy": | |
return "☁️" | |
if icon == "partly-cloudy-day": | |
return "🌤" | |
if icon == "partly-cloudy-night": | |
return "☁️" | |
print(iconEmoji(icon) + " Currently " + summary + " and " + str(temperature) + "°F") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment