Course Hero Logo

testie.py - # Wilhelm Wang # wilhelaw uci.edu # 42005266 #...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 2 out of 2 pages.

# Wilhelm Wang# [email protected]# 42005266# APIkey: 1e7fa6b1d18f20fbafb694fb400e118cimport urllib, jsonfrom urllib import request,errorfrom WebAPI import WebAPIclass OpenWeather(WebAPI):def __init__(self, zipcode, ccode):self.zipcode = zipcodeself.ccode = ccodeself.apikey = ''#def _download_url and set_apikey are inherited from class WebAPIdef load_data(self) -> None:response = Noner_obj = Noneurl = f"{self.zipcode},{self.ccode}&appid={self.apikey}"try:response = urllib.request.urlopen(url)#print(response.code)json_results = response.read()r_obj = json.loads(json_results)except urllib.error.HTTPError as e:print('Failed to download contents of URL')print('Status code: {}'.format(e.code))if e.code == 404:print('requested resource is not available on the server')if e.code == 503:print('remote API is currently unavailable')if e.code == 401:print('unauthorized access to API')else:print(e)except urllib.error.URLError as e:print(e)print('Loss of local connection to the Internet')finally:if response != None:response.close()

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 2 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
N/A
Tags
CCode

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture