''' 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 = 'http://forecast.weather.gov/zipcity.php?inputstring='
# get zipcode of interest
zipcode = input( 'Enter zipcode: ' )
# specify complete query
query_link = WEATHER_GOV_QUERY + zipcode
# print( query_link )
# get response from weather.gov
page = url.get_text( query_link )
# print( page )
# forecast delimiters
OPENING_DELIMITER = '
'
# this string is in front of the forecast that we actually want
CLOSING_DELIMITER = '
'
# this string is after the forecast we actually want
# to get the forecast, itself, we need to find the forecast
opening_delimiter_start_index = page.index( OPENING_DELIMITER ) # page is just a string, so you can look for other strings within it
closing_delimiter_start_index = page.index( CLOSING_DELIMITER, opening_delimiter_start_index )
# print( opening_delimiter_start_index, closing_delimiter_start_index )
forecast_start_index = opening_delimiter_start_index + len(OPENING_DELIMITER)
forecast_end_index = closing_delimiter_start_index
# ready to get and print the forecast
forecast = page[ forecast_start_index : forecast_end_index ]
print(forecast)
## BTW This tells you where the name of the city starts
'Extended Forecast for\n\t'
'
'