Create the api request endpoint {0: default, 1: zipcode, 2: city_name}
(endpoint_type=0)
| 128 | |
| 129 | |
| 130 | def create_endpoint(endpoint_type=0): |
| 131 | """ Create the api request endpoint |
| 132 | {0: default, 1: zipcode, 2: city_name}""" |
| 133 | if endpoint_type == 1: |
| 134 | try: |
| 135 | endpoint = f"http://api.openweathermap.org/data/2.5/weather?zip={APP_DATA['Postal']},{APP_DATA['Country']}&appid={API_KEY}&units={APP_DATA['Units']}" |
| 136 | return endpoint |
| 137 | except ConnectionError: |
| 138 | return |
| 139 | elif endpoint_type == 2: |
| 140 | try: |
| 141 | # endpoint = f"http://api.openweathermap.org/data/2.5/weather?q={APP_DATA['City'].replace(' ', '%20')},us&APPID={API_KEY}&units={APP_DATA['Units']}" |
| 142 | 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']}" |
| 143 | return endpoint |
| 144 | except ConnectionError: |
| 145 | return |
| 146 | else: |
| 147 | return |
| 148 | |
| 149 | |
| 150 | def request_weather_data(endpoint): |