Define defaults for Post IDs to None
This commit is contained in:
parent
7ad2dcbe0d
commit
53155f02a8
1 changed files with 12 additions and 8 deletions
20
scl.py
20
scl.py
|
@ -196,18 +196,20 @@ with Session(engine) as session:
|
|||
)
|
||||
updated_entries.append("")
|
||||
updated_entries.append(hashtag_string)
|
||||
mastodon_post_result = mastodon.status_post(
|
||||
post_result = mastodon.status_post(
|
||||
status="\n".join(updated_entries),
|
||||
in_reply_to_id=existing_record.most_recent_post_id,
|
||||
visibility="public",
|
||||
language="en",
|
||||
)
|
||||
existing_record.most_recent_post_id = mastodon_post_result["id"]
|
||||
existing_record.most_recent_post_id = post_result["id"]
|
||||
|
||||
session.commit()
|
||||
|
||||
except NoResultFound:
|
||||
print("Existing record not found")
|
||||
post_id = None
|
||||
map_media_post_id = None
|
||||
if not event_class["is_postable"]:
|
||||
print(
|
||||
"Outage is {} considered postable, will not post".format(
|
||||
|
@ -346,6 +348,7 @@ with Session(engine) as session:
|
|||
mime_type="image/png",
|
||||
description=alt_text,
|
||||
)
|
||||
map_media_post_id = map_media_post["id"]
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
@ -375,19 +378,20 @@ with Session(engine) as session:
|
|||
)
|
||||
)
|
||||
|
||||
mastodon_post_result = mastodon.status_post(
|
||||
post_result = mastodon.status_post(
|
||||
status=post_text,
|
||||
media_ids=map_media_post,
|
||||
visibility="public",
|
||||
language="en",
|
||||
)
|
||||
post_id = post_result["id"]
|
||||
|
||||
new_outage_record = SclOutage(
|
||||
scl_outage_id=event["id"],
|
||||
outage_user_id=event["identifier"],
|
||||
most_recent_post_id=mastodon_post_result["id"],
|
||||
initial_post_id=mastodon_post_result["id"],
|
||||
map_media_post_id=map_media_post["id"],
|
||||
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"],
|
||||
|
@ -405,7 +409,7 @@ with Session(engine) as session:
|
|||
for active_outage in session.scalars(lookup_active_outages_statement):
|
||||
if not any(event["id"] == active_outage.scl_outage_id for event in scl_events):
|
||||
# Event ID no longer exists in response
|
||||
mastodon_post_result = mastodon.status_post(
|
||||
post_result = mastodon.status_post(
|
||||
status="This outage is reported to be resolved.\n\n#SeattleCityLightOutage #SCLOutage #SCLOutage{}".format(
|
||||
active_outage.outage_user_id
|
||||
),
|
||||
|
@ -414,6 +418,6 @@ with Session(engine) as session:
|
|||
language="en",
|
||||
)
|
||||
|
||||
active_outage.most_recent_post_id = mastodon_post_result["id"]
|
||||
active_outage.most_recent_post_id = post_result["id"]
|
||||
active_outage.no_longer_in_response_time = datetime.now()
|
||||
session.commit()
|
||||
|
|
Loading…
Reference in a new issue