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("")
|
||||||
updated_entries.append(hashtag_string)
|
updated_entries.append(hashtag_string)
|
||||||
mastodon_post_result = mastodon.status_post(
|
post_result = mastodon.status_post(
|
||||||
status="\n".join(updated_entries),
|
status="\n".join(updated_entries),
|
||||||
in_reply_to_id=existing_record.most_recent_post_id,
|
in_reply_to_id=existing_record.most_recent_post_id,
|
||||||
visibility="public",
|
visibility="public",
|
||||||
language="en",
|
language="en",
|
||||||
)
|
)
|
||||||
existing_record.most_recent_post_id = mastodon_post_result["id"]
|
existing_record.most_recent_post_id = post_result["id"]
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
except NoResultFound:
|
except NoResultFound:
|
||||||
print("Existing record not found")
|
print("Existing record not found")
|
||||||
|
post_id = None
|
||||||
|
map_media_post_id = None
|
||||||
if not event_class["is_postable"]:
|
if not event_class["is_postable"]:
|
||||||
print(
|
print(
|
||||||
"Outage is {} considered postable, will not post".format(
|
"Outage is {} considered postable, will not post".format(
|
||||||
|
@ -346,6 +348,7 @@ with Session(engine) as session:
|
||||||
mime_type="image/png",
|
mime_type="image/png",
|
||||||
description=alt_text,
|
description=alt_text,
|
||||||
)
|
)
|
||||||
|
map_media_post_id = map_media_post["id"]
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(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,
|
status=post_text,
|
||||||
media_ids=map_media_post,
|
media_ids=map_media_post,
|
||||||
visibility="public",
|
visibility="public",
|
||||||
language="en",
|
language="en",
|
||||||
)
|
)
|
||||||
|
post_id = post_result["id"]
|
||||||
|
|
||||||
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"],
|
||||||
most_recent_post_id=mastodon_post_result["id"],
|
most_recent_post_id=post_id,
|
||||||
initial_post_id=mastodon_post_result["id"],
|
initial_post_id=post_id,
|
||||||
map_media_post_id=map_media_post["id"],
|
map_media_post_id=map_media_post_id,
|
||||||
last_updated_time=last_updated_time,
|
last_updated_time=last_updated_time,
|
||||||
estimated_restoration_time=estimated_restoration_time,
|
estimated_restoration_time=estimated_restoration_time,
|
||||||
cause=event["cause"],
|
cause=event["cause"],
|
||||||
|
@ -405,7 +409,7 @@ with Session(engine) as session:
|
||||||
for active_outage in session.scalars(lookup_active_outages_statement):
|
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):
|
if not any(event["id"] == active_outage.scl_outage_id for event in scl_events):
|
||||||
# Event ID no longer exists in response
|
# 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(
|
status="This outage is reported to be resolved.\n\n#SeattleCityLightOutage #SCLOutage #SCLOutage{}".format(
|
||||||
active_outage.outage_user_id
|
active_outage.outage_user_id
|
||||||
),
|
),
|
||||||
|
@ -414,6 +418,6 @@ with Session(engine) as session:
|
||||||
language="en",
|
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()
|
active_outage.no_longer_in_response_time = datetime.now()
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
Loading…
Reference in a new issue