From 11f85b565d68cb1080c128d6715d88c385a1e3c5 Mon Sep 17 00:00:00 2001 From: Liam Steckler Date: Thu, 10 Jul 2025 16:07:40 -0700 Subject: [PATCH] Cleanup/refactor of do_initial_post returns --- scl.py | 60 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/scl.py b/scl.py index b0b3791..507df9d 100644 --- a/scl.py +++ b/scl.py @@ -260,7 +260,7 @@ def do_initial_post( start_time: datetime, estimated_restoration_time: datetime, outage_geometries: shapely.MultiPolygon, -) -> dict[str, str | None]: +) -> str: post_id = None map_media_post = None area_text = str() @@ -311,7 +311,7 @@ Cause: {} ) post_id = post_result["id"] - return {"post_id": post_id, "map_media_post_id": None} + return post_id class Base(DeclarativeBase): @@ -326,7 +326,6 @@ class SclOutage(Base): outage_user_id: Mapped[str] = mapped_column() most_recent_post_id: Mapped[Optional[str]] = mapped_column() initial_post_id: Mapped[Optional[str]] = mapped_column() - map_media_post_id: Mapped[Optional[str]] = mapped_column() last_updated_time: Mapped[datetime] = mapped_column() estimated_restoration_time: Mapped[datetime] = mapped_column() cause: Mapped[str] = mapped_column() @@ -341,7 +340,7 @@ class SclOutage(Base): geometries_modified: Mapped[Optional[bool]] = 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}, neighborhood={self.neighborhood!r}, city={self.city!r}, outage_geometries={self.outage_geometries!r}, geometries_modified={self.geometries_modified!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}, 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}, outage_geometries={self.outage_geometries!r}, geometries_modified={self.geometries_modified!r})" engine = create_engine("sqlite:///scl.db") @@ -458,30 +457,28 @@ with Session(engine) as session: print( "Posting an event that grew above the threshold required to post" ) - initial_post_result = do_initial_post( + post_id = do_initial_post( event, event_class, start_time, estimated_restoration_time, outage_geometries, ) - try: - existing_record.neighborhood = initial_post_result[ - "neighborhood" - ] - except KeyError: - pass + # TODO: It doesn't look like these would have been set- where? + # try: + # existing_record.neighborhood = initial_post_result[ + # "neighborhood" + # ] + # except KeyError: + # pass - try: - existing_record.city = initial_post_result["city"] - 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[ - "map_media_post_id" - ] + existing_record.initial_post_id = post_id + existing_record.most_recent_post_id = post_id else: print("Existing record was found, and no properties were updated.") session.commit() @@ -489,7 +486,6 @@ with Session(engine) as session: except NoResultFound: print("Existing record not found") post_id = None - map_media_post_id = None neighborhood = None city = None if not event_class["is_postable"]: @@ -499,32 +495,30 @@ with Session(engine) as session: ) ) else: - initial_post_result = do_initial_post( + post_id = do_initial_post( event, event_class, start_time, estimated_restoration_time, outage_geometries, ) - post_id = initial_post_result["post_id"] - map_media_post_id = initial_post_result["map_media_post_id"] - try: - neighborhood = initial_post_result["neighborhood"] - except KeyError: - pass + # TODO: It doesn't look like these would have been set- where? + # try: + # neighborhood = initial_post_result["neighborhood"] + # except KeyError: + # pass - try: - city = initial_post_result["city"] - except KeyError: - pass + # try: + # city = initial_post_result["city"] + # except KeyError: + # pass new_outage_record = SclOutage( scl_outage_id=event["id"], outage_user_id=event["identifier"], most_recent_post_id=post_id, initial_post_id=post_id, - map_media_post_id=map_media_post_id, last_updated_time=last_updated_time, estimated_restoration_time=estimated_restoration_time, cause=event["cause"],