Created
April 13, 2023 19:17
-
-
Save ibuys/d4c429da77b6a13a470789f90ba51b49 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 | |
LAT = "" | |
LONG = "" | |
APIKEY = "" | |
request_url = f"https://api.openweathermap.org/data/2.5/weather?lat={LAT}&lon=-{LONG}&appid={APIKEY}&units=imperial" | |
response = urlopen( | |
request_url, | |
context=ssl._create_unverified_context(), | |
).read() | |
data = json.loads(response) | |
summary = data["weather"][0]["description"] | |
temperature = data["main"]["temp"] | |
icon = data["weather"][0]["icon"] | |
def icon_emoji(icon): | |
if icon == "01d": | |
return "☀️" | |
if icon == "01n": | |
return "🌕" | |
if icon == "02d": | |
return "🌤" | |
if icon == "02n": | |
return "☁️" | |
if icon == "03d": | |
return "🌤" | |
if icon == "03n": | |
return "☁️" | |
if icon == "04d": | |
return "🌤" | |
if icon == "04n": | |
return "☁️" | |
if icon == "09d": | |
return "🌧" | |
if icon == "10n": | |
return "⛈️" | |
if icon == "13n": | |
return "❄️" | |
if icon == "13d": | |
return "❄️" | |
if icon == "50n": | |
return "🌫" | |
if icon == "50d": | |
return "🌪️" | |
if icon == "09d": | |
return "🌦️" | |
if icon == "10d": | |
return "🌦️" | |
summary = summary.title() | |
print(f"{icon_emoji(icon)} {summary} and {str(temperature)} °F") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment