mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Added weather code and Readme. Enjoy
This commit is contained in:
parent
a04df11006
commit
6f82bc473e
8
Current_City_Weather/README.md
Normal file
8
Current_City_Weather/README.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Current City Weather
|
||||
Uses a GET request to retrieve details on your current weather details within your city, simply insert the name of any
|
||||
city and it will provide details such as current temperature, current wind speed and current weather type.
|
||||
|
||||
usage: Go to Current_City_Weather directory and run Weather.py and ad
|
||||
|
||||
|
||||
|
39
Current_City_Weather/Weather.py
Normal file
39
Current_City_Weather/Weather.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import requests
|
||||
|
||||
|
||||
def get_temperature(json_data):
|
||||
temp_in_celcius = json_data['main']['temp']
|
||||
return temp_in_celcius
|
||||
|
||||
def get_weather_type(json_data):
|
||||
weather_type = json_data['weather'][0]['description']
|
||||
return weather_type
|
||||
|
||||
def get_wind_speed(json_data):
|
||||
wind_speed = json_data['wind']['speed']
|
||||
return wind_speed
|
||||
|
||||
|
||||
|
||||
def get_weather_data(json_data, city):
|
||||
description_of_weather = json_data['weather'][0]['description']
|
||||
weather_type = get_weather_type(json_data)
|
||||
temperature = get_temperature(json_data)
|
||||
wind_speed = get_wind_speed(json_data)
|
||||
weather_details = ''
|
||||
return weather_details + ("The weather in {} is currently {} with a temperature of {} degrees and wind speeds reaching {} km/ph".format(city, weather_type, temperature, wind_speed))
|
||||
|
||||
|
||||
def main():
|
||||
api_address = 'https://api.openweathermap.org/data/2.5/weather?q=Sydney,au&appid=a10fd8a212e47edf8d946f26fb4cdef8&q='
|
||||
city = input("City Name : ")
|
||||
units_format = "&units=metric"
|
||||
final_url = api_address + city + units_format
|
||||
json_data = requests.get(final_url).json()
|
||||
weather_details = get_weather_data(json_data, city)
|
||||
# print formatted data
|
||||
print(weather_details)
|
||||
|
||||
|
||||
|
||||
main()
|
Loading…
Reference in New Issue
Block a user