mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-23 20:11:10 +00:00
Merge pull request #49 from noobyysauraj/master
Simple script for printing Weather Reports.
This commit is contained in:
commit
9e1086e9fa
13
scripts/Weather_Reports/README.md
Normal file
13
scripts/Weather_Reports/README.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
## Py-Weather-Report
|
||||
Simple Python Program for Printing Weather report of specified region.
|
||||
>_Uses https://rapidapi.com/weatherapi/api/weatherapi-com for API Calls._
|
||||
### Requirements
|
||||
```bash
|
||||
pip install json requests
|
||||
```
|
||||
|
||||
### Run Program
|
||||
```bash
|
||||
python script.py
|
||||
```
|
||||
|
30
scripts/Weather_Reports/script.py
Normal file
30
scripts/Weather_Reports/script.py
Normal file
|
@ -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"
|
||||
)
|
Loading…
Reference in New Issue
Block a user