''' Purpose: provide weather forecast by accessing US Weather Service web service Usage: user provides a zipcode Output: municipality and state combo along with its current forecast ''' # get url access capabilities from cs 1112 module import url # define weather.gov base query WEATHER_GOV_QUERY = 'https://forecast.weather.gov/zipcity.php?inputstring=' # forecast delimiters FRONT_DELIMITER = 'forecast-text">' # text that precedes forecast REAR_DELIMITER = '' # text that follows forecast # delimiter lengths LENGTH_FRONT_DELIMITER = len( FRONT_DELIMITER ) LENGTH_REAR_DELIMITER = len( REAR_DELIMITER ) # get zipcode of interest reply = input( 'Enter zipcode: ' ) zipcode = reply.strip() # clean-up response # specify complete query query_link = WEATHER_GOV_QUERY + zipcode # get response from weather.gov text = url.get_text( query_link ) # to get the forecast, we need to find it within the text # start by finding the forecast delimiters front_index = ... rear_index = ... forecast = text[ front_index : rear_index ] print( forecast ) print() # get the indices for the front and rear of the forecast forecast_start = ... forecast_rear = ... # ready to get and print the forecast forecast = text[ forecast_start : forecast_rear + 1 ] # print the forecast print( forecast )