From 08a7ab7488fd4071fcb683c18500c98942b57a68 Mon Sep 17 00:00:00 2001 From: Tanmoy Sengupta <65300045+TSG405@users.noreply.github.com> Date: Sun, 23 Oct 2022 19:31:19 +0530 Subject: [PATCH 1/4] Create Weather_Update.py --- Weather_Updater/Weather_Update.py | 68 +++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Weather_Updater/Weather_Update.py diff --git a/Weather_Updater/Weather_Update.py b/Weather_Updater/Weather_Update.py new file mode 100644 index 0000000..0390432 --- /dev/null +++ b/Weather_Updater/Weather_Update.py @@ -0,0 +1,68 @@ +# import required modules +import requests, json + +# Enter your API key here +api_key = "Your_API_Key" + +# base_url variable to store url +base_url = "http://api.openweathermap.org/data/2.5/weather?" + +# Give city name +city_name = input("Enter city name : ") + +# complete_url variable to store +# complete url address +complete_url = base_url + "appid=" + api_key + "&q=" + city_name + +# get method of requests module +# return response object +response = requests.get(complete_url) + +# json method of response object +# convert json format data into +# python format data +x = response.json() + +# Now x contains list of nested dictionaries +# Check the value of "cod" key is equal to +# "404", means city is found otherwise, +# city is not found +if x["cod"] != "404": + + # store the value of "main" + # key in variable y + y = x["main"] + + # store the value corresponding + # to the "temp" key of y + current_temperature = y["temp"] + + # store the value corresponding + # to the "pressure" key of y + current_pressure = y["pressure"] + + # store the value corresponding + # to the "humidity" key of y + current_humidity = y["humidity"] + + # store the value of "weather" + # key in variable z + z = x["weather"] + + # store the value corresponding + # to the "description" key at + # the 0th index of z + weather_description = z[0]["description"] + + # print following values + print(" Temperature (in kelvin unit) = " + + str(current_temperature) + + "\n atmospheric pressure (in hPa unit) = " + + str(current_pressure) + + "\n humidity (in percentage) = " + + str(current_humidity) + + "\n description = " + + str(weather_description)) + +else: + print(" City Not Found ") From 12630036fd20c956be6ef5aad7641bad165b34a4 Mon Sep 17 00:00:00 2001 From: Tanmoy Sengupta <65300045+TSG405@users.noreply.github.com> Date: Sun, 23 Oct 2022 19:36:55 +0530 Subject: [PATCH 2/4] Signed-off-by: TSG405 From 0e98570a95d4cee7e96453afd3ad2f5d72fc75f3 Mon Sep 17 00:00:00 2001 From: Tanmoy Sengupta <65300045+TSG405@users.noreply.github.com> Date: Sun, 23 Oct 2022 20:07:24 +0530 Subject: [PATCH 3/4] Tanmoy Sengupta 65300045+TSG405@users.noreply.github.com --- Weather_Updater/Weather_Update.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Weather_Updater/Weather_Update.py b/Weather_Updater/Weather_Update.py index 0390432..e32c67e 100644 --- a/Weather_Updater/Weather_Update.py +++ b/Weather_Updater/Weather_Update.py @@ -32,7 +32,6 @@ # store the value of "main" # key in variable y y = x["main"] - # store the value corresponding # to the "temp" key of y current_temperature = y["temp"] From eff547eb3f2cbb2a01f654def726163bde759899 Mon Sep 17 00:00:00 2001 From: Tanmoy Sengupta <65300045+TSG405@users.noreply.github.com> Date: Sun, 23 Oct 2022 20:08:36 +0530 Subject: [PATCH 4/4] Signed-off-by: Tanmoy Sengupta 65300045+TSG405@users.noreply.github.com