diff --git a/scl.py b/scl.py index e92335d..c8d002e 100644 --- a/scl.py +++ b/scl.py @@ -290,9 +290,11 @@ class SclOutage(Base): start_time: Mapped[datetime] = mapped_column() num_people: Mapped[int] = mapped_column() max_num_people: Mapped[int] = mapped_column() + neighborhood: Mapped[Optional[str]] = mapped_column() + city: Mapped[Optional[str]] = mapped_column() def __repr__(self) -> str: - return f"SclOutage(scl_outage_id={self.scl_outage_id!r}, most_recent_post_id={self.most_recent_post_id!r}, initial_post_id={self.initial_post_id!r}, map_media_post_id={self.map_media_post_id!r}, last_updated_time={self.last_updated_time!r}, no_longer_in_response_time={self.no_longer_in_response_time!r}), start_time={self.start_time!r}), num_people={self.num_people!r}), max_num_people={self.max_num_people!r})" + return f"SclOutage(scl_outage_id={self.scl_outage_id!r}, most_recent_post_id={self.most_recent_post_id!r}, initial_post_id={self.initial_post_id!r}, map_media_post_id={self.map_media_post_id!r}, last_updated_time={self.last_updated_time!r}, no_longer_in_response_time={self.no_longer_in_response_time!r}, start_time={self.start_time!r}, num_people={self.num_people!r}, max_num_people={self.max_num_people!r}, neighborhood={self.neighborhood!r}, city={self.city!r})" engine = create_engine("sqlite:///scl.db") @@ -396,6 +398,18 @@ with Session(engine) as session: estimated_restoration_time, outage_geometries, ) + try: + existing_record.neighborhood = initial_post_result[ + "neighborhood" + ] + except KeyError: + pass + + try: + existing_record.city = initial_post_result["city"] + except KeyError: + pass + existing_record.initial_post_id = initial_post_result["post_id"] existing_record.most_recent_post_id = initial_post_result["post_id"] existing_record.map_media_post_id = initial_post_result[ @@ -424,6 +438,18 @@ with Session(engine) as session: post_id = initial_post_result["post_id"] map_media_post_id = initial_post_result["map_media_post_id"] + neighborhood = str() + try: + neighborhood = initial_post_result["neighborhood"] + except KeyError: + pass + + city = str() + try: + city = initial_post_result["city"] + except KeyError: + pass + new_outage_record = SclOutage( scl_outage_id=event["id"], outage_user_id=event["identifier"], @@ -437,6 +463,8 @@ with Session(engine) as session: start_time=start_time, num_people=event["numPeople"], max_num_people=event["numPeople"], + neighborhood=neighborhood, + city=city, ) session.add(new_outage_record) session.commit()