Skip to content

Commit ef3e171

Browse files
committed
Make Weather Forecast App - Python API
Make Weather Forecast App - Python API
1 parent e52791a commit ef3e171

File tree

8 files changed

+96
-0
lines changed

8 files changed

+96
-0
lines changed

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.name

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/python____project.iml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import tkinter as tk
2+
import requests
3+
import time
4+
5+
6+
def getWeather(canvas):
7+
city = textField.get()
8+
api = "https://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=f01e80368f05c66b03425d3f08ab1a1c"
9+
10+
json_data = requests.get(api).json()
11+
condition = json_data['weather'][0]['main']
12+
temp = int(json_data['main']['temp'] - 273.15)
13+
min_temp = int(json_data['main']['temp_min'] - 273.15)
14+
max_temp = int(json_data['main']['temp_max'] - 273.15)
15+
pressure = json_data['main']['pressure']
16+
humidity = json_data['main']['humidity']
17+
wind = json_data['wind']['speed']
18+
sunrise = time.strftime('%I:%M:%S', time.gmtime(json_data['sys']['sunrise'] - 21600))
19+
sunset = time.strftime('%I:%M:%S', time.gmtime(json_data['sys']['sunset'] - 21600))
20+
21+
final_info = condition + "\n" + str(temp) + "°C"
22+
final_data = "\n" + "Min Temp: " + str(min_temp) + "°C" + "\n" + "Max Temp: " + str(
23+
max_temp) + "°C" + "\n" + "Pressure: " + str(pressure) + "\n" + "Humidity: " + str(
24+
humidity) + "\n" + "Wind Speed: " + str(wind) + "\n" + "Sunrise: " + sunrise + "\n" + "Sunset: " + sunset
25+
label1.config(text=final_info)
26+
label2.config(text=final_data)
27+
28+
29+
canvas = tk.Tk()
30+
canvas.geometry("600x500")
31+
canvas.title("Weather App")
32+
f = ("poppins", 15, "bold")
33+
t = ("poppins", 35, "bold")
34+
35+
textField = tk.Entry(canvas, justify='center', width=20, font=t)
36+
textField.pack(pady=20)
37+
textField.focus()
38+
textField.bind('<Return>', getWeather)
39+
40+
label1 = tk.Label(canvas, font=t)
41+
label1.pack()
42+
label2 = tk.Label(canvas, font=f)
43+
label2.pack()
44+
canvas.mainloop()

0 commit comments

Comments
 (0)