Log city and neighborhood to the database for upcoming post editing
Some checks failed
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/vulnerability-scan Pipeline failed

This commit is contained in:
Liam Steckler 2024-10-27 08:49:32 -07:00
parent b98a39629c
commit 1aa5ea0975

30
scl.py
View file

@ -290,9 +290,11 @@ class SclOutage(Base):
start_time: Mapped[datetime] = mapped_column() start_time: Mapped[datetime] = mapped_column()
num_people: Mapped[int] = mapped_column() num_people: Mapped[int] = mapped_column()
max_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: 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") engine = create_engine("sqlite:///scl.db")
@ -396,6 +398,18 @@ with Session(engine) as session:
estimated_restoration_time, estimated_restoration_time,
outage_geometries, 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.initial_post_id = initial_post_result["post_id"]
existing_record.most_recent_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[ 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"] post_id = initial_post_result["post_id"]
map_media_post_id = initial_post_result["map_media_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( new_outage_record = SclOutage(
scl_outage_id=event["id"], scl_outage_id=event["id"],
outage_user_id=event["identifier"], outage_user_id=event["identifier"],
@ -437,6 +463,8 @@ with Session(engine) as session:
start_time=start_time, start_time=start_time,
num_people=event["numPeople"], num_people=event["numPeople"],
max_num_people=event["numPeople"], max_num_people=event["numPeople"],
neighborhood=neighborhood,
city=city,
) )
session.add(new_outage_record) session.add(new_outage_record)
session.commit() session.commit()