Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
WeatherBot/WeatherAPI.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
43 lines (34 sloc)
1.55 KB
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
# https://www.youtube.com/watch?v=D8-snVfekto | |
# The First function callweather API is taken from here | |
import requests | |
import json | |
class Weather: | |
def callWeatherAPI(cityName): | |
api_key = '' # Our unique key for accessing the api | |
link = 'https://api.openweathermap.org/data/2.5/weather' # A call which takes the city and outputs data | |
city = cityName # Lets you input a desired city | |
call = {'APPID': api_key, 'q': city} # Takes the two parameters required by the API | |
output = requests.get(link, params=call) # Calls the API with the two things it requested as variables | |
data = output.json() # stores the incoming data | |
return(data) # Displays incoming data | |
def callForecastAPI(lat, lon): | |
api_key = '' | |
link = 'https://api.openweathermap.org/data/2.5/onecall' | |
units = "imperial" | |
call = {'lat': lat, 'lon': lon, 'APPID': api_key, 'units': units} | |
output = requests.get(link, params=call) | |
data = output.json() | |
return data | |
#print("hi") | |
def callForecastAPIdate(lat, lon, date): | |
api_key = '' | |
link = 'https://api.openweathermap.org/data/2.5/onecall' | |
units = "imperial" | |
call = {'lat': lat, 'lon': lon, 'APPID': api_key, 'dt':date, 'units': units} | |
output = requests.get(link, params=call) | |
data = output.json() | |
print(data) | |
return data | |
callForecastAPIdate(35, 139, 1605916800) | |
#callForecastAPI(35, 139 ) | |
#callWeatherAPI("London") |