From a8256e8289cbc113950d9a0c1d119eea416c26d8 Mon Sep 17 00:00:00 2001 From: noobyysauraj Date: Sun, 2 Oct 2022 17:56:54 +0530 Subject: [PATCH] Initial : Add weather report script Simple Python Program for Printing Weather report of specified region. --- scripts/Weather_Reports/script.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 scripts/Weather_Reports/script.py diff --git a/scripts/Weather_Reports/script.py b/scripts/Weather_Reports/script.py new file mode 100644 index 0000000..7ad26b0 --- /dev/null +++ b/scripts/Weather_Reports/script.py @@ -0,0 +1,30 @@ +import requests +import json +loc = str(input("Enter Location : ")) +url = "https://weatherapi-com.p.rapidapi.com/current.json" + +querystring = {"q":loc} + +headers = { + "X-RapidAPI-Key": "bdfb49f730mshb9aca5467ecee49p121eeajsn6be212dbf15d", + "X-RapidAPI-Host": "weatherapi-com.p.rapidapi.com" +} + +response = requests.request("GET", url, headers=headers, params=querystring) +json_str = json.dumps(response.text) +y = json.loads(response.text) +print( +"\n\n", +"------------------------------------------\n", +"Name : ", y["location"]["name"], "\n", +"Region : " , y["location"]["region"], "\n", +"Country : " , y["location"]["country"], "\n", +"Latitude : " , y["location"]["lat"], "\n", +"Longitude : " , y["location"]["lon"], "\n", +"------------------------------------------\n", +"Temeperature : " , y["current"]["temp_c"], "°C\n", +"Wind Speed : " , y["current"]["wind_kph"], "kmh\n", +"Wind Degree : " , y["current"]["wind_degree"], "°\n", +"Wind Direction : " , y["current"]["wind_dir"], "\n", +"------------------------------------------\n" +) \ No newline at end of file