Created
September 23, 2020 14:03
-
-
Save zakirangwala/4f117ac404f5d9a1d8c3aa1458be25c6 to your computer and use it in GitHub Desktop.
Tutorial code : Get weather data
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 config | |
# Check Weather | |
def weather(latitude, longitude): | |
try: | |
api_key = config.api_key | |
base_url = 'http://api.openweathermap.org/data/2.5/weather?' | |
complete_url = base_url + "lat=" + \ | |
str(latitude) + "&lon=" + str(longitude) + "&appid=" + api_key | |
response = requests.get(complete_url) | |
x = response.json() | |
except Exception as e: | |
print("An error occurred while retrieving weather information") | |
speak("An error occurred while retrieving weather information") | |
if x["cod"] != "404": | |
return x | |
else: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment