From a5b0479b84c8a6bd49e829a46b958d6d8a328cef Mon Sep 17 00:00:00 2001 From: Alper Date: Wed, 21 Aug 2024 18:03:09 +0200 Subject: [PATCH] Update main.py There is a change in BBC weather which made the previous script obsolete. --- examples/python-data-scraper/main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/python-data-scraper/main.py b/examples/python-data-scraper/main.py index 2c4009401f..02e2d7dfd4 100644 --- a/examples/python-data-scraper/main.py +++ b/examples/python-data-scraper/main.py @@ -30,13 +30,13 @@ # to know when do the results start if day_offset == 0: # Get the timezone offset written in the page footer and parse it - tz_description = soup.find_all(class_='wr-c-footer-timezone__item')[1].text - tz_offset_match = re.search(r'([+-]\d\d)(\d\d)', tz_description) - tz_offset_hours = int(tz_offset_match.group(1)) - tz_offset_minutes = int(tz_offset_match.group(2)) + time_zone_paragraph = soup.find('p', text=lambda x: x and 'All times are' in x) + tz_description = time_zone_paragraph.text + gmt_offset = re.search(r'GMT([+-]\d+)', tz_description) + tz_offset_hours = int(gmt_offset.group(1)) # Get the current date and time at the scraped location - timezone_offset = timedelta(hours=tz_offset_hours, minutes=tz_offset_minutes) + timezone_offset = timedelta(hours=tz_offset_hours) location_timezone = timezone(timezone_offset) location_current_datetime = datetime.now(tz=location_timezone)