mikeckennedy / python-jumpstart-course-demos

Contains all the "handout" materials for my Python Jumpstart by Building 10 Apps course. This includes try it yourself and finished versions of the 10 apps.
https://talkpython.fm/course
MIT License
746 stars 536 forks source link

Jan 2020 Wunderground changed their site so the recorded presentation doesn't work #46

Closed mikeckennedy closed 4 years ago

mikeckennedy commented 4 years ago

As of Jan 2020, Wunderground changed their site so the video as recorded, doesn't work. Here's what you need to change.

First, see that the URL has changed from zipcode to state/city, for example:

https://www.wunderground.com/weather/us/or/portland

That means you'll need to ask for state and city rather than zipcode from the user and pass that to get_html_from_web. This should work now:

# Note: wunderground changed it's URL structure, zipcode no longer works.
# We need to pass state and city (sorry folks outside the US).
# You can update the URL for your country.
state = input('What US state do you want the weather for (e.g. OR)? ')
city = input('What city in {} (e.g. Portland)? ')

html = get_html_from_web(state, city)

Additionally, the CSS selectors have changed to the following:

cityCss = 'h1'
weatherScaleCss = '.wu-unit-temperature .wu-label'
weatherTempCss = '.wu-unit-temperature .wu-value'
weatherConditionCss = '.condition-icon'

Finally, cleanup of the city H1 text needs to change just a little:

loc = soup.find('h1').get_text() \
    .replace(' Weather Conditions', '') \
    .replace('star_ratehome', '')

Sorry for the trouble, but we can't force them to not change the site.

mikeckennedy commented 4 years ago

Closing this because we are updating the video. You can still comment on it.

thanhtien1123 commented 4 years ago

I am having problems at this part of the program. Any chance you could help? Thanks

chronoviking commented 4 years ago

Actually, this still isn't quite correct.

When asking for city, you include placeholder for state, but don't include any format. It should read

    state = input('What US state do you want the weather for (e.g. OR)? ')
    city = input('What city in [{}] (e.g. Portland)? '.format(state))

This would make the url in get_html_from_web(state, city):

    url = 'https://www.wunderground.com/weather/us/{}/{}'.format(state.lower(), city.lower())
mikeckennedy commented 4 years ago

Hi, yes, this looks like a nice little user-friendly addition @chronoviking Thanks.