Created
December 2, 2019 22:57
-
-
Save aliceh/0234a0c720b20f783803e8bd2a49add9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import re | |
api_key = "d7457467f2492af08b5aa255be8b2e2e" | |
base_url = "http://api.openweathermap.org/data/2.5/weather?" | |
cities="61.210841,-149.888735\nSan Francisco\n33132,us" | |
def process_city_list(list): | |
modified_list=[] | |
list=list.split('\n') | |
for name in list: | |
name_parts=name.split(',') | |
if len(name_parts)==1: | |
city_name="&q=" + name | |
elif name_parts[1].isalpha(): | |
city_name='&zip='+ name | |
else: | |
city_name='&lat='+ name_parts[0] + '&lon=' + name_parts[1] | |
modified_list.append(city_name) | |
return(modified_list) | |
def find_max_temperature(city_list): | |
list=process_city_list(city_list) | |
temp=[] | |
for city in list: | |
complete_url = base_url + "appid=" + api_key + city | |
response = requests.get(complete_url) | |
data=response.json() | |
temp.append(data['main']['temp']) | |
max_temp=max(temp) | |
return(max_temp) | |
if __name__=='__main__': | |
print(find_max_temperature(cities)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment