File tree Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ config.py
Original file line number Diff line number Diff line change
1
+ # Get Weather Details of a city
2
+
3
+ ## How to Run?
4
+ + Run ` python3 weather.py <location-name> `
5
+ + The output will present the weather details of the mentioned city
6
+
7
+ ## Example
8
+ ![ image] ( images/weather.png )
Original file line number Diff line number Diff line change
1
+ import requests
2
+ import json
3
+ import sys
4
+ from colorama import Fore , init
5
+ import config
6
+ # Autoreset on for Colorama
7
+ init (autoreset = True )
8
+ # Getting API Key from Config.py
9
+ api_key = config .api_key
10
+ # If the user doesn't enter the location
11
+ if len (sys .argv ) != 2 :
12
+ print ("Enter location" )
13
+ location = sys .argv [1 ]
14
+ # Calling the API
15
+ url = f"https://api.openweathermap.org/data/2.5/weather?q={ location } &units=metric&appid={ api_key } "
16
+ response = requests .get (url )
17
+ data = json .loads (response .text )
18
+ print (Fore .CYAN + "Weather Details for the city " + data ["name" ])
19
+ print (Fore .BLUE + "Weather : " + data ["weather" ][0 ]["main" ])
20
+ print (Fore .BLUE + "Temperature is " + str (data ["main" ]["temp" ]) + "°C and it feels like " + str (data ["main" ]["feels_like" ]) + "°C" )
21
+ print (Fore .BLUE + "Wind Speed is " + str (data ["wind" ]["speed" ]) + " m/sec" )
You can’t perform that action at this time.
0 commit comments