From 940c626bbe86bca6b37b4ba0d8730e9cbfb4b2e3 Mon Sep 17 00:00:00 2001 From: Liam Steckler Date: Thu, 10 Jul 2025 12:56:38 -0700 Subject: [PATCH] Format the list of updated properties into a nicer sentence --- posttext.py | 11 +++++++++++ scl.py | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 posttext.py diff --git a/posttext.py b/posttext.py new file mode 100644 index 0000000..22d6264 --- /dev/null +++ b/posttext.py @@ -0,0 +1,11 @@ +from collections.abc import Sequence + + +def list_to_sentence(list: Sequence[str]) -> str: + match len(list): + case 0: + return str() + case 1: + return list[0] + case _: + return " and ".join((", ".join(list[0:-1]), list[-1])) diff --git a/scl.py b/scl.py index c7fe219..b517b23 100644 --- a/scl.py +++ b/scl.py @@ -17,6 +17,7 @@ from sqlalchemy.exc import NoResultFound from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column from geospatial import DBGeometry, convert_outage_geometry +from posttext import list_to_sentence REQUESTS_HEADERS = {"User-Agent": "seattlecitylight-mastodon-bot"} POST_DATETIME_FORMAT = "%b %e %l:%M %p" @@ -433,11 +434,10 @@ with Session(engine) as session: ), ) else: - # TODO: this currently just smashes all of the properties together with commas, it'd be nice to make it actually format it like a sentence updated_entries.insert( 0, "The {} of this outage have been updated.\n".format( - ", ".join(updated_properties) + list_to_sentence(updated_properties) ), ) if max_event_class["is_postable"] and existing_record.initial_post_id: