From a35755592c387c54fb90a220783ea25cdcdac2c0 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Fri, 27 Jan 2023 13:07:54 -0600 Subject: [PATCH] refactor: streamlining of main function Update utilizing walrus operators, only importing the sub-namespace we need from os & sys. --- autowl/__main__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/autowl/__main__.py b/autowl/__main__.py index b014ecc..b597726 100644 --- a/autowl/__main__.py +++ b/autowl/__main__.py @@ -1,16 +1,16 @@ -import os import discord +from os import environ +from sys import stderr # main runtime function def main(): - try: - disToken = os.environ['DISCORD_TOKEN'] # grabs the discord token from the environment variable, if not there, exit - except: - print("ERROR: unable to find discord token in environment variables!") + if disToken := environ.get('DISCORD_TOKEN'): + print(f"Received discord token: {disToken}") + # Call into main action here, basically launch the bot via import to a lower module + else: + print("Unable to access DISCORD_TOKEN in environment!", file=stderr) exit(1) - print("hello world") - main()