Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# PythonReview2
Weather Checker Python App

0) Make sure that you have Python 3 installed (python 3.8 is the best option for now)
1) Install python Requests module and python Tkinter module
2) After downloading the files inside the directory of WeatherApp project and type into the terminal: python3 app.py
(this command will launch the project)
3 changes: 3 additions & 0 deletions WeatherApp/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3"
}
Binary file added WeatherApp/__pycache__/tokens.cpython-38.pyc
Binary file not shown.
68 changes: 68 additions & 0 deletions WeatherApp/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import tkinter as tk
import requests
from tkinter import font
import tokens

def getWeather(city) :
search = {'APPID': apiKey, 'q': city, 'units': 'metric'}
try :
response = requests.get(url, search)
weather = response.json()
output = []
name = weather['name'] + " " + weather['sys']['country']
status = weather['weather'][0]['description']
temperature = weather['main']['temp']
windspeed = weather['wind']['speed']
humidity = weather['main']['humidity']
pressure = weather['main']['pressure']

output.append(name)
output.append(status)
output.append(temperature)
output.append(windspeed)
output.append(humidity)
output.append(pressure)
except :
output = []

formattedOutput(output)

def formattedOutput(output) :
try :
text = "Weather status in : " + output[0] + "\n conditions : " + output[1] + "\ntemperature : " + str(output[2]) + "C"
text += "\nwind speed : " + str(output[3]) + "m/sec\n" + "pressure : " + str(output[5]) + "mBar\n" + "humidity : " + str(output[4]) + "%\n"
except:
text = "Error in getting response.\nCheck your input and network connection"
label['text'] = text

SIZE = [550, 800]

root = tk.Tk()
root.title("Instant Weather Checker by Pavel Grigorev")
root.maxsize(800, 550)
root.minsize(650, 300)

canvas = tk.Canvas(root, height = SIZE[0], width = SIZE[1])
canvas.pack()

backgroung = tk.PhotoImage(file = "WeatherApp/media/weather.png")
backgroungLabel = tk.Label(root, image = backgroung)
backgroungLabel.place(relwidth = 1, relheight = 1, )

upperFrame = tk.Frame(root, bg = '#3B6EC9', bd = 5)
upperFrame.place(relx = 0.5, rely = 0.1, relwidth = 0.85, relheight = 0.1, anchor = "n")

textBox = tk.Entry(upperFrame, bg = "white", font = ('Courier New', 20))
textBox.insert(0,"Input City Name or Coordinates")
textBox.place(relwidth = 0.65, relheight = 1)

button = tk.Button(upperFrame, text="Check Weather", font = ('Courier New', 20), command = lambda: getWeather(textBox.get()))
button.place(relx = 0.7, relheight = 1, relwidth = 0.3)

lowerFrame = tk.Frame(root, bg = "#3B6EC9", bd = 10)
lowerFrame.place(relx = 0.5, rely = 0.25, relwidth = 0.85, relheight = 0.6, anchor = "n")

label = tk.Label(lowerFrame, text = "", bg = "white", font = ('Courier New', 20))
label.place(relx = 0, rely = 0, relwidth = 1, relheight = 1)

root.mainloop()
Binary file added WeatherApp/media/weather.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions WeatherApp/tokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apiKey = '8233ee406d8a49ed7163013ed6f90527'
url = 'https://api.openweathermap.org/data/2.5/weather'