Skip to content

Instantly share code, notes, and snippets.

@ibuys
Created July 28, 2022 17:51
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 ibuys/5bbd51b10bf7dab26fa379d09b02b18d to your computer and use it in GitHub Desktop.
Save ibuys/5bbd51b10bf7dab26fa379d09b02b18d to your computer and use it in GitHub Desktop.
#!/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