""" Purpose: provide weather forecast by accessing US Weather Service Usage: user provides a zipcode Output: current forecast for that zipcode """ # get access to web-based data support import url # set base weather.gov query WEATHER_GOV_QUERY = "https://forecast.weather.gov/zipcity.php?inputstring=" # get zipcode of interest reply = input( "Enter zipcode: " ) zipcode = reply.strip() # set complete query link link = WEATHER_GOV_QUERY + zipcode # query weather.gov page = url.get_contents( link ) # need to find the forecast within the page # forecast delimiters FRONT_DELIMITER = "
" # text preceding forecast REAR_DELIMITER = "
" # text following forecast # delimiter lengths LENGTH_FRONT_DELIMITER = len( FRONT_DELIMITER ) LENGTH_REAR_DELIMITER = len( REAR_DELIMITER ) # start by finding the forecast delimiters front_index = ... rear_index = ... #print( "front_index:", front_index ) #print( "rear_index:", rear_index ) # get and print the forecast forecast = page[ front_index : rear_index ] print( zipcode, "forecast:", forecast )