Skip to content

Commit 186b16e

Browse files
committed
Addition of county to the Weather Desktop Widget
1 parent 58e0b2c commit 186b16e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

DemoPrograms/Demo_Desktop_Widget_Weather.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
This widget is an early version of a PSG Widget so it may not share the same names / constructs as the templates.
2626
27-
Copyright 2020 PySimpleGUI - www.PySimpleGUI.com
27+
Copyright 2020, 2022 PySimpleGUI - www.PySimpleGUI.com
2828
2929
"""
3030

@@ -76,6 +76,7 @@ def change_settings(settings, window_location=(None, None)):
7676

7777
layout = [[sg.T('Enter Zipcode or City for your location')],
7878
[sg.I(settings.get('-location-', nearest_postal), size=(15, 1), key='-LOCATION-')],
79+
[sg.I(settings.get('-country-', 'US'), size=(15, 1), key='-COUNTRY-')],
7980
[sg.I(settings.get('-api key-', ''), size=(32, 1), key='-API KEY-')],
8081
[sg.B('Ok', border_width=0, bind_return_key=True), sg.B('Register For a Key', border_width=0, k='-REGISTER-'), sg.B('Cancel', border_width=0)], ]
8182

@@ -91,6 +92,7 @@ def change_settings(settings, window_location=(None, None)):
9192

9293
if event == 'Ok':
9394
user_location = settings['-location-'] = values['-LOCATION-']
95+
settings['-country-'] = values['-COUNTRY-']
9496
API_KEY = settings['-api key-'] = values['-API KEY-']
9597
else:
9698
API_KEY = settings['-api key-']
@@ -103,6 +105,7 @@ def change_settings(settings, window_location=(None, None)):
103105
else:
104106
APP_DATA['City'] = user_location
105107
APP_DATA['Postal'] = ''
108+
APP_DATA['Country'] = settings['-country-']
106109

107110
return settings
108111

@@ -119,13 +122,14 @@ def create_endpoint(endpoint_type=0):
119122
{0: default, 1: zipcode, 2: city_name}"""
120123
if endpoint_type == 1:
121124
try:
122-
endpoint = f"http://api.openweathermap.org/data/2.5/weather?zip={APP_DATA['Postal']},us&appid={API_KEY}&units={APP_DATA['Units']}"
125+
endpoint = f"http://api.openweathermap.org/data/2.5/weather?zip={APP_DATA['Postal']},{APP_DATA['Country']}&appid={API_KEY}&units={APP_DATA['Units']}"
123126
return endpoint
124127
except ConnectionError:
125128
return
126129
elif endpoint_type == 2:
127130
try:
128-
endpoint = f"http://api.openweathermap.org/data/2.5/weather?q={APP_DATA['City'].replace(' ', '%20')},us&APPID={API_KEY}&units={APP_DATA['Units']}"
131+
# endpoint = f"http://api.openweathermap.org/data/2.5/weather?q={APP_DATA['City'].replace(' ', '%20')},us&APPID={API_KEY}&units={APP_DATA['Units']}"
132+
endpoint = f"http://api.openweathermap.org/data/2.5/weather?q={APP_DATA['City'].replace(' ', '%20')},{APP_DATA['Country']}&APPID={API_KEY}&units={APP_DATA['Units']}"
129133
return endpoint
130134
except ConnectionError:
131135
return
@@ -246,6 +250,7 @@ def main(refresh_rate, win_location):
246250
# Load settings from config file. If none found will create one
247251
settings = load_settings()
248252
location = settings['-location-']
253+
APP_DATA['Country'] = settings.get('-country-', 'US')
249254
if location is not None:
250255
if location.isnumeric() and len(location) == 5 and location is not None:
251256
APP_DATA['Postal'] = location

0 commit comments

Comments
 (0)