Skip to content

Instantly share code, notes, and snippets.

@zakirangwala
Created September 23, 2020 14:03
Show Gist options
  • Save zakirangwala/4f117ac404f5d9a1d8c3aa1458be25c6 to your computer and use it in GitHub Desktop.
Save zakirangwala/4f117ac404f5d9a1d8c3aa1458be25c6 to your computer and use it in GitHub Desktop.
Tutorial code : Get weather data
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