-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.py
More file actions
48 lines (40 loc) · 1.76 KB
/
engine.py
File metadata and controls
48 lines (40 loc) · 1.76 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import tkinter as tk
import requests
import time
def getWeather(canvas):
city = textField.get()
textfield= ("Enter City Name")
api = "https://api.openweathermap.org/data/2.5/weather?q="+city+"&appid=514dfb44dc2f1748b699f5e29bc55d50"
json_data = requests.get(api).json()
condition = json_data['weather'][0]['main']
temp = int(json_data['main']['temp'] - 273.15)
min_temp = int(json_data['main']['temp_min'] - 273.15)
max_temp = int(json_data['main']['temp_max'] - 273.15)
pressure = json_data['main']['pressure']
humidity = json_data['main']['humidity']
wind = json_data['wind']['speed']
sunrise = time.strftime('%I:%M:%S', time.gmtime(json_data['sys']['sunrise'] - 21600))
sunset = time.strftime('%I:%M:%S', time.gmtime(json_data['sys']['sunset'] - 21600))
final_info = condition + "\n" + str(temp) + "°C"
final_data = "\n"+ "Min Temp: " + str(min_temp) + "°C" + "\n" + "Max Temp: " + str(max_temp) + "°C" +"\n" + "Pressure: " + str(pressure) + "\n" +"Humidity: " + str(humidity) + "\n" +"Wind Speed: " + str(wind) + "\n" + "Sunrise: " + sunrise + "\n" + "Sunset: " + sunset
label1.config(text = final_info)
label2.config(text = final_data)
canvas = tk.Tk()
canvas.geometry("400x550")
canvas.title("Rahul's Weather App")
f = ("Times", 20,"bold")
t = ("Times", 30, "bold")
k = ("poppins" , 10,"bold")
textField = tk.Entry(canvas, justify='center', width = 18, font = f)
textField.pack(pady = 30)
textField.focus()
textField.bind('<Return>', getWeather)
label1=tk.Label(canvas,text="Enter City", font=f)
label1.pack()
label2 = tk.Label(canvas, font=f)
label2.pack()
label3 = tk.Label(canvas, font=t)
label3.pack()
label4 = tk.Label(canvas, justify='right',text="Copyright for Dev-Jr",font=k)
label4.pack()
canvas.mainloop()