diff --git a/scl.py b/scl.py index f0f8a55..b0b3791 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, -) -> str: +) -> dict[str, str | None]: post_id = None map_media_post = None area_text = str() @@ -311,7 +311,7 @@ Cause: {} ) post_id = post_result["id"] - return post_id + return {"post_id": post_id, "map_media_post_id": None} class Base(DeclarativeBase): @@ -326,6 +326,7 @@ 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() @@ -340,7 +341,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}, 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}, 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})" engine = create_engine("sqlite:///scl.db") @@ -414,14 +415,7 @@ with Session(engine) as session: existing_record.max_num_people = event["numPeople"] max_event_class = classify_event_size(existing_record.max_num_people) if existing_record.outage_geometries != outage_geometries: - print( - "Geometries modified. Equals: {}, DE-9IM: {}, Within: {}".format( - outage_geometries.equals(existing_record.outage_geometries), - outage_geometries.relate(existing_record.outage_geometries), - outage_geometries.within(existing_record.outage_geometries), - ) - ) - + print("Geometries modified") updated_properties.append("area") existing_record.outage_geometries = outage_geometries existing_record.geometries_modified = True @@ -464,28 +458,30 @@ with Session(engine) as session: print( "Posting an event that grew above the threshold required to post" ) - post_id = do_initial_post( + initial_post_result = do_initial_post( event, event_class, start_time, estimated_restoration_time, outage_geometries, ) - # 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.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 = post_id - existing_record.most_recent_post_id = post_id + 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" + ] else: print("Existing record was found, and no properties were updated.") session.commit() @@ -493,6 +489,7 @@ 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"]: @@ -502,30 +499,32 @@ with Session(engine) as session: ) ) else: - post_id = do_initial_post( + initial_post_result = 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"] - # TODO: It doesn't look like these would have been set- where? - # try: - # neighborhood = initial_post_result["neighborhood"] - # except KeyError: - # pass + 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"],