Added user-friendly CLI

This commit is contained in:
2023-03-12 22:14:03 +01:00
parent 48acab2d5e
commit c670db72fa
4 changed files with 154 additions and 84 deletions

View File

@@ -1,94 +1,16 @@
from os import sep, remove, getpid
from shutil import move
from os import getpid
from sys import exit
from argparse import ArgumentParser
from modules.cli import *
from modules.logger import logWrite
from modules.scheduler import scheduler
from modules.utils import configGet, jsonLoad, jsonSave, killProc, locale
# Args =====================================================================================================================================
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,
)
except FileNotFoundError:
logWrite(
locale(
"move_sent_doesnt_exist", "console", locale=configGet("locale")
).format(entry)
)
except Exception as exp:
logWrite(
locale(
"move_sent_doesnt_exception", "console", locale=configGet("locale")
).format(entry, exp)
)
logWrite(locale("move_sent_completed", "console", locale=configGet("locale")))
if args.cleanup:
if args.confirm:
index = jsonLoad(configGet("index", "locations"))
for entry in index["sent"]:
try:
try:
remove(configGet("queue", "locations") + sep + entry)
except FileNotFoundError:
pass
try:
remove(configGet("sent", "locations") + sep + entry)
except FileNotFoundError:
pass
except Exception as exp:
logWrite(
locale(
"cleanup_exception", "console", locale=configGet("locale")
).format(entry, exp)
)
jsonSave(index, jsonLoad(configGet("index", "locations")))
logWrite(locale("cleanup_completed", "console", locale=configGet("locale")))
else:
logWrite(locale("cleanup_unathorized", "console", locale=configGet("locale")))
if args.cleanup_index:
if args.confirm:
index = jsonLoad(configGet("index", "locations"))
index["sent"] = []
jsonSave(index, jsonLoad(configGet("index", "locations")))
logWrite(
locale("cleanup_index_completed", "console", locale=configGet("locale"))
)
else:
logWrite(
locale("cleanup_index_unathorized", "console", locale=configGet("locale"))
)
if args.norun:
logWrite(locale("passed_norun", "console", locale=configGet("locale_log")))
exit()
# ===========================================================================================================================================
from modules.utils import configGet, killProc, locale
# Import ===================================================================================================================================
try:
from modules.app import app
from pyrogram.sync import idle
from modules.app import app
except ModuleNotFoundError:
print(locale("deps_missing", "console", locale=configGet("locale")), flush=True)
exit()