From 50f2d89b4fd7cfc34ad39474b23d00232dcbb718 Mon Sep 17 00:00:00 2001 From: SpaceSaver Date: Thu, 16 Nov 2023 16:58:16 -0500 Subject: [PATCH] Fix some mistakes and add the potential for a None --- demo.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/demo.py b/demo.py index 87df6c7..2262f5b 100644 --- a/demo.py +++ b/demo.py @@ -81,7 +81,8 @@ async def main(args: argparse.Namespace): users = ids.register(conn, users, vd, args.client_data or args.reg_notify) return users - def expiration_identifier(users: list[ids.IDSUser]) -> datetime.datetime: + def expiration_identifier(users: list[ids.IDSUser]) -> datetime.datetime | None: + expiration = None # Format time as HH:MM:SS PM/AM EST/EDT (X minutes from now) expire_msg = lambda expiration: f"Number registration is valid until {str(expiration.astimezone().strftime('%x %I:%M:%S %p %Z'))} ({str(int((expiration - datetime.datetime.now(datetime.timezone.utc)).total_seconds()/60))} minutes from now)" for user in users: @@ -94,6 +95,7 @@ async def main(args: argparse.Namespace): # Make it a UTC aware timezone, for reasons expiration = expiration.replace(tzinfo=datetime.timezone.utc) logging.info(expire_msg(expiration)) + return expiration async def reregister(conn: apns.APNSConnection, users: list[ids.IDSUser]) -> datetime.datetime: @@ -218,6 +220,9 @@ async def main(args: argparse.Namespace): expiration = await reregister(conn, users) else: expiration = expiration_identifier(users) + + if expiration is None: + expiration = await reregister(conn, users) while True: reregister_time = expiration - datetime.timedelta(minutes=wait_time_minutes) # wait_time_minutes before expiration