Created
January 2, 2022 04:28
-
-
Save Ppang0405/690821a60283da68df09d1ac83e0d08c 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 /Users/truongnguyen/.asdf/shims/python | |
# coding: UTF-8 | |
import requests | |
icons = dict({ | |
"01d":"☀️" , | |
"02d":"⛅️" , | |
"03d":"☁️" , | |
"04d":"☁️" , | |
"09d":"\uD83C\uDF27" , | |
"10d":"\uD83C\uDF26" , | |
"11d":"⛈" , | |
"13d":"❄️" , | |
"50d":"\uD83C\uDF2B" , | |
"01n":"\uD83C\uDF11" , | |
"02n":"\uD83C\uDF11 ☁" , | |
"03n":"☁️" , | |
"04n":"️️☁☁" , | |
"09n":"\uD83C\uDF27" , | |
"10n":"☔️" , | |
"11n":"⛈" , | |
"13n":"❄️" , | |
"50n":"\uD83C\uDF2B" | |
}) | |
country = "Hanoi" | |
app_id = "c833730aa8d4c58f4e8637c62cd21ee0" | |
def kelvinToCelsius(kelvin): | |
return kelvin - 273.15 | |
r = requests.get(f"https://api.openweathermap.org/data/2.5/weather?q={country}&appid={app_id}") | |
json_response = r.json() | |
print(f"{country}: {icons[json_response['weather'][0]['icon']]} {kelvinToCelsius(json_response['main']['temp'])}ºC") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment