Skip to content

Commit

Permalink
Comments, cleaner config, exit if no token in main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-fatal committed Feb 11, 2023
1 parent 072d8b7 commit ae147d4
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
from message import get_chat_id
from monitor import monitor
import toml
import sys


def load_config():
config_path = "config.toml"
with open(config_path) as file:
config = toml.load(file)
if config["chat_id"] == "":
chat_id = None
while not chat_id:
input("Please send a message to the Telegram bot you created. Once done, wait 1 minute then press Enter.")
chat_id = get_chat_id(config["token"])
config["chat_id"] = chat_id
with open(config_path, "w") as file:
toml.dump(config, file)
config_location = "config.toml"
with open(config_location) as file:
config = toml.load(file) # Make a dict of the config values

if not config["token"]: # No token supplied
sys.exit("Please enter a token in the config file")
while not config["chat_id"]: # Keep trying to find chat id until we get a valid one
input("Please send a message to the Telegram bot you created. Once done, wait 1 \
minute then press Enter. If it doesn't work, send another message then try \
again.")
config["chat_id"] = get_chat_id(config["token"])

with open(config_location, "w") as file:
toml.dump(config, file) # Output new config (to file) with updated chat id
return config


def main():
config = load_config()
monitor(config["path"], config["token"], config["chat_id"])
monitor(config)


if __name__ == "__main__":
Expand Down

0 comments on commit ae147d4

Please sign in to comment.