diff --git a/README.md b/README.md index 19b65c4..26ad374 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/WeatherApp/.vscode/settings.json b/WeatherApp/.vscode/settings.json new file mode 100644 index 0000000..62b24db --- /dev/null +++ b/WeatherApp/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3" +} \ No newline at end of file diff --git a/WeatherApp/__pycache__/tokens.cpython-38.pyc b/WeatherApp/__pycache__/tokens.cpython-38.pyc new file mode 100644 index 0000000..d136527 Binary files /dev/null and b/WeatherApp/__pycache__/tokens.cpython-38.pyc differ diff --git a/WeatherApp/app.py b/WeatherApp/app.py new file mode 100644 index 0000000..45f3296 --- /dev/null +++ b/WeatherApp/app.py @@ -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() diff --git a/WeatherApp/media/weather.png b/WeatherApp/media/weather.png new file mode 100644 index 0000000..2a7bfde Binary files /dev/null and b/WeatherApp/media/weather.png differ diff --git a/WeatherApp/tokens.py b/WeatherApp/tokens.py new file mode 100644 index 0000000..be857fa --- /dev/null +++ b/WeatherApp/tokens.py @@ -0,0 +1,2 @@ +apiKey = '8233ee406d8a49ed7163013ed6f90527' +url = 'https://api.openweathermap.org/data/2.5/weather' \ No newline at end of file