-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTempTracker.py
More file actions
28 lines (21 loc) · 792 Bytes
/
TempTracker.py
File metadata and controls
28 lines (21 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import requests
import json
API_KEY = '674f4f59440ce3c5f050b58d10bee8bc'
URL = f"https://api.openweathermap.org/data/2.5/weather"
def get_current_temperature(city):
params = {
'q': city,
'appid': API_KEY,
'units': 'metric' # Request temperature in Celsius
}
# 'imperial' for Fahrenheit
# 'standard' for Kelvin
response = requests.get(URL, params=params)
data = json.loads(response.text)
print(data) # Print the complete API response for inspection
temp = data['main']['temp']
return temp
print("Welcome to Temperature Tracker Project Created by Indir Solanki\n")
city_name = input("Enter city name: ")
temperature = get_current_temperature(city_name)
print(f"\nThe current temperature in {city_name} is {temperature}°C.")