Skip to content

Commit

Permalink
TN: Events: fixes for some TZ issues
Browse files Browse the repository at this point in the history
  • Loading branch information
showerst committed Nov 24, 2024
1 parent 67a5660 commit 6f8fa3a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions scrapers/tn/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from utils.events import match_coordinates
from spatula import HtmlPage, URL, XPath, SelectorError, PdfPage

import dateutil
import pytz
import re

Expand Down Expand Up @@ -54,6 +55,7 @@ def process_page(self):
class TNEventScraper(Scraper, LXMLMixin):
_tz = pytz.timezone("US/Central")
_utc = pytz.timezone("UTC")
_tzmapping = {"CST": "US/Central"}

def scrape(self, chamber=None):
if chamber:
Expand Down Expand Up @@ -112,8 +114,6 @@ def scrape_chamber(self, chamber=None):
location = f"{location}, 600 Dr. Martin L King, Jr. Blvd, Nashville, TN 37243"

description = metainf["type"].text_content()
dtfmt = "%A, %B %d, %Y %I:%M %p"
dtfmt_no_time = "%A, %B %d, %Y"
# skipping cancelled here instead of setting a status, because
# they clear the time on canceled events so we can't look them up
if time == "Cancelled":
Expand All @@ -132,12 +132,11 @@ def scrape_chamber(self, chamber=None):
continue

datetime_string = datetime_string.strip()

try:
when = dt.datetime.strptime(datetime_string, dtfmt)
except ValueError:
when = dt.datetime.strptime(datetime_string, dtfmt_no_time)
when = self._utc.localize(when)
when = dateutil.parser.parse(
datetime_string, tzinfos=self._tzmapping
)
if when.tzinfo is None:
when = self._tz.localize(when)

event = Event(
name=description,
Expand Down

0 comments on commit 6f8fa3a

Please sign in to comment.