Skip to content

Commit 380ddce

Browse files
authored
fix: Update main.py (#1157)
There is a change in BBC weather which made the previous script obsolete.
1 parent cbccb4e commit 380ddce

File tree

1 file changed

+5
-5
lines changed
  • examples/python-data-scraper

1 file changed

+5
-5
lines changed

examples/python-data-scraper/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
# to know when do the results start
3131
if day_offset == 0:
3232
# Get the timezone offset written in the page footer and parse it
33-
tz_description = soup.find_all(class_='wr-c-footer-timezone__item')[1].text
34-
tz_offset_match = re.search(r'([+-]\d\d)(\d\d)', tz_description)
35-
tz_offset_hours = int(tz_offset_match.group(1))
36-
tz_offset_minutes = int(tz_offset_match.group(2))
33+
time_zone_paragraph = soup.find('p', text=lambda x: x and 'All times are' in x)
34+
tz_description = time_zone_paragraph.text
35+
gmt_offset = re.search(r'GMT([+-]\d+)', tz_description)
36+
tz_offset_hours = int(gmt_offset.group(1))
3737

3838
# Get the current date and time at the scraped location
39-
timezone_offset = timedelta(hours=tz_offset_hours, minutes=tz_offset_minutes)
39+
timezone_offset = timedelta(hours=tz_offset_hours)
4040
location_timezone = timezone(timezone_offset)
4141

4242
location_current_datetime = datetime.now(tz=location_timezone)

0 commit comments

Comments
 (0)