From 7a7f3868917a5bb74972b2d82108068d61d9ddd2 Mon Sep 17 00:00:00 2001 From: profitroll Date: Thu, 3 Nov 2022 12:10:59 +0100 Subject: [PATCH] Is now using argparse library --- poster.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/poster.py b/poster.py index fc47fc3..932c43c 100644 --- a/poster.py +++ b/poster.py @@ -6,12 +6,26 @@ from threading import Thread from time import time from traceback import format_exc from pathlib import Path +from argparse import ArgumentParser from modules.logging import logWrite from modules.utils import configGet, jsonLoad, jsonSave, killProc, locale # Args ===================================================================================================================================== -if "--move-sent" in argv: +parser = ArgumentParser( + prog = "Telegram Poster", + description = "Bot for posting some of your stuff and also receiving submissions." +) + +parser.add_argument("-m", "--move-sent", action="store_true") +parser.add_argument("-c", "--cleanup", action="store_true") +parser.add_argument("--confirm", action="store_true") +parser.add_argument("-i", "--cleanup-index", action="store_true") +parser.add_argument("-n", "--norun", action="store_true") + +args = parser.parse_args() + +if args.move_sent: for entry in jsonLoad(configGet("index", "locations"))["sent"]: try: move(configGet("queue", "locations")+sep+entry, configGet("sent", "locations")+sep+entry) @@ -21,8 +35,8 @@ if "--move-sent" in argv: logWrite(locale("move_sent_doesnt_exception", "console", locale=configGet("locale")).format(entry, exp)) logWrite(locale("move_sent_completed", "console", locale=configGet("locale"))) -if "--cleanup" in argv: - if "--confirm" in argv: +if args.cleanup: + if args.confirm: index = jsonLoad(configGet("index", "locations")) for entry in index["sent"]: try: @@ -41,8 +55,8 @@ if "--cleanup" in argv: else: logWrite(locale("cleanup_unathorized", "console", locale=configGet("locale"))) -if "--cleanup-index" in argv: - if "--confirm" in argv: +if args.cleanup_index: + if args.confirm: index = jsonLoad(configGet("index", "locations")) index["sent"] = [] jsonSave(index, jsonLoad(configGet("index", "locations"))) @@ -50,7 +64,7 @@ if "--cleanup-index" in argv: else: logWrite(locale("cleanup_index_unathorized", "console", locale=configGet("locale"))) -if "--norun" in argv: +if args.norun: logWrite(locale("passed_norun", "console", locale=configGet("locale"))) exit() #===========================================================================================================================================