Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather App Made by python using tkinter #135

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
77 changes: 77 additions & 0 deletions Weather Tkinter/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import PySimpleGUI as sg
from bs4 import BeautifulSoup as bs
import requests

def get_weather_data(location):
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36"
url = f'https://www.google.com/search?q=weather+{location.replace(" ","")}'
session = requests.Session()
session.headers['User-Agent'] = USER_AGENT
html = session.get(url)

# create a new soup
soup = bs(html.text, "html.parser")
name = soup.find("div", attrs={'id': 'wob_loc'}).text
time = soup.find("div", attrs={'id': 'wob_dts'}).text
weather = soup.find("span", attrs={'id': 'wob_dc'}).text
temp = soup.find("span", attrs={'id': 'wob_tm'}).text
return name, time, weather, temp

weather_column = sg.Column([
[sg.Image('',key = '-IMAGE-', background_color = '#FFFFFF',)]],
key = '-LEFT-',
background_color = '#FFFFFF')

info_column = sg.Column([
[sg.Text('', key = '-LOCATION-', font = 'Calibri 30', background_color = '#FF0000', pad = 0, visible = False)],
[sg.Text('', key = '-TIME-', font = 'Calibri 16', background_color = '#000000', text_color = '#FFFFFF', pad = 0, visible = False)],
[sg.Text('', key = '-TEMP-', font = 'Calibri 16', pad = (0,10), background_color = '#FFFFFF', text_color = '#000000', justification = 'center', visible = False)]
],key = '-RIGHT-',
background_color = '#FFFFFF')

main_layout = [
[sg.Input(key = '-INPUT-',expand_x = True),sg.Button('submit', button_color = '#000000')],
[weather_column,info_column]
]

sg.theme('reddit')
window = sg.Window('Weather', main_layout)

while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break

if event == 'submit':
name, time, weather, temp = get_weather_data(values['-INPUT-'])

window['-LOCATION-'].update(name, visible = True)
window['-TIME-'].update(time.split(' ')[0], visible = True)
window['-TEMP-'].update(f'{temp} \u2103 ({weather})', visible = True)

# sun
# if weather in ('Sun','Sunny','Clear','Clear with periodic clouds', 'Mostly sunny'):
# window['-IMAGE-'].update('symbols/sun.png')

# # part sun
# if weather in ('Partly Sunny','Mostly Sunny','Partly cloudy','Mostly cloudy','Cloudy','Overcast'):
# window['-IMAGE-'].update('symbols/part sun.png')

# # rain
# if weather in ('Rain','Chance of Rain','Light Rain','Showers','Scattered Showers','Rain and Snow','Hail'):
# window['-IMAGE-'].update('symbols/rain.png')

# # thunder
# if weather in ('Scattered Thunderstorms','Chance of Storm','Storm','Thunderstorm','Chance of TStorm'):
# window['-IMAGE-'].update('symbols/thunder.png')

# # foggy
# if weather in ('Mist','Dust','Fog','Smoke','Haze','Flurries'):
# window['-IMAGE-'].update('symbols/fog.png')

# # snow
# if weather in ('Freezing Drizzle','Chance of Snow','Sleet','Snow','Icy','Snow Showers'):
# window['-IMAGE-'].update('symbols/snow.png')


window.close()
2 changes: 2 additions & 0 deletions Weather Tkinter/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is a Simple Weather App You Just Need To Enter The Correct Place Name And it will display its weather .
![image](https://user-images.githubusercontent.com/61025539/194692495-201c509b-59c4-40ac-acbd-f4b2b0fd372f.png)