diff --git a/city_scrapers/spiders/chi_citycouncil.py b/city_scrapers/spiders/chi_citycouncil.py index 66bd8fd45..ab33c05a7 100644 --- a/city_scrapers/spiders/chi_citycouncil.py +++ b/city_scrapers/spiders/chi_citycouncil.py @@ -1,6 +1,9 @@ +from datetime import datetime + from city_scrapers_core.constants import NOT_CLASSIFIED from city_scrapers_core.items import Meeting from city_scrapers_core.spiders import CityScrapersSpider +from dateutil import tz from dateutil.parser import parser @@ -47,18 +50,30 @@ def _parse_classification(self, item): def _parse_start(self, item): """Parse start datetime as a naive datetime object.""" - full_date = item["date"] - - date = full_date.split("T")[0] - time = full_date.split("T")[1] - time = time.split("+")[0] + # as of 11/10/2023, the returned time is in UTC timezone - # as of 11/10/2023 the returned time is 5 hrs ahead of actual meeting time - - adjusted_hour = int(time.split(":")[0]) - 5 - adjusted_time = str(adjusted_hour) + ":" + time.split(":", 1)[1] - # print(adjusted_time) - return parser().parse(date + " " + adjusted_time) + # retieve meeting date and time + full_date = item["date"] + # print(full_date) + + # convert datetime from UTC to CST time + # turn datetime object into datetime timzone aware object + from_zone = tz.gettz("UTC") + to_zone = tz.gettz("CST") + + utc = datetime.strptime(full_date.split("+")[0] + "Z", "%Y-%m-%dT%H:%M:%SZ") + utc = utc.replace(tzinfo=from_zone) + cst = utc.astimezone(to_zone) + # print(utc) + # print(cst) + + # extract the individual date and time as strings + # get date component + date = cst.strftime("%m/%d/%Y %H:%M:%S").split(" ")[0] + # get time component + time = cst.strftime("%m/%d/%Y %H:%M:%S").split(" ")[1] + + return parser().parse(date + " " + time) def _parse_end(self, item): """Parse end datetime as a naive datetime object. Added by pipeline if None"""