From 4422a13ba9a413a19533922e1510a1e08892b30c Mon Sep 17 00:00:00 2001 From: Profitroll <47523801+profitrollgame@users.noreply.github.com> Date: Wed, 22 Mar 2023 10:33:21 +0100 Subject: [PATCH] Improved async context --- poster.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/poster.py b/poster.py index ea43709..c2d6860 100644 --- a/poster.py +++ b/poster.py @@ -116,10 +116,11 @@ if configGet("post", "mode"): # uvloop.install() # asyncio.run(main()) -if __name__ == "__main__": + +async def main(): logWrite(locale("startup", "console").format(str(pid))) - app.start() + await app.start() if configGet("startup", "reports"): try: @@ -133,7 +134,7 @@ if __name__ == "__main__": ), ) if downtime.days >= 1: - app.send_message( + await app.send_message( configGet("owner"), locale( "startup_downtime_days", @@ -141,7 +142,7 @@ if __name__ == "__main__": ).format(pid, downtime.days), ) elif downtime.hours >= 1: - app.send_message( + await app.send_message( configGet("owner"), locale( "startup_downtime_hours", @@ -149,7 +150,7 @@ if __name__ == "__main__": ).format(pid, downtime.hours), ) else: - app.send_message( + await app.send_message( configGet("owner"), locale( "startup_downtime_minutes", @@ -158,7 +159,7 @@ if __name__ == "__main__": ).format(pid, downtime.minutes), ) else: - app.send_message( + await app.send_message( configGet("owner"), locale("startup", "message").format(pid), ) @@ -175,10 +176,10 @@ if __name__ == "__main__": # if len(get(f'{configGet("address", "posting", "api")}/albums?q={configGet("queue", "posting", "api", "albums")}', headers={"Authorization": f"Bearer {token}"}).json()["results"]) == 0: # post(f'{configGet("address", "posting", "api")}/albums?name={configGet("queue", "posting", "api", "albums")}&title={configGet("queue", "posting", "api", "albums")}', headers={"Authorization": f"Bearer {token}"}) - idle() + await idle() try: - app.send_message( + await app.send_message( configGet("owner"), locale("shutdown", "message").format(pid), ) @@ -197,4 +198,7 @@ if __name__ == "__main__": scheduler.shutdown() - killProc(pid) + +if __name__ == "__main__": + loop = asyncio.get_event_loop() + loop.run_until_complete(main())