Now using black for formatting
This commit is contained in:
62
poster.py
62
poster.py
@@ -9,8 +9,8 @@ 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."
|
||||
prog="Telegram Poster",
|
||||
description="Bot for posting some of your stuff and also receiving submissions.",
|
||||
)
|
||||
|
||||
parser.add_argument("-m", "--move-sent", action="store_true")
|
||||
@@ -24,11 +24,22 @@ 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)
|
||||
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))
|
||||
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_doesnt_exception", "console", locale=configGet("locale")
|
||||
).format(entry, exp)
|
||||
)
|
||||
logWrite(locale("move_sent_completed", "console", locale=configGet("locale")))
|
||||
|
||||
if args.cleanup:
|
||||
@@ -37,15 +48,19 @@ if args.cleanup:
|
||||
for entry in index["sent"]:
|
||||
try:
|
||||
try:
|
||||
remove(configGet("queue", "locations")+sep+entry)
|
||||
remove(configGet("queue", "locations") + sep + entry)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
try:
|
||||
remove(configGet("sent", "locations")+sep+entry)
|
||||
remove(configGet("sent", "locations") + sep + entry)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
except Exception as exp:
|
||||
logWrite(locale("cleanup_exception", "console", locale=configGet("locale")).format(entry, 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:
|
||||
@@ -56,14 +71,18 @@ if args.cleanup_index:
|
||||
index = jsonLoad(configGet("index", "locations"))
|
||||
index["sent"] = []
|
||||
jsonSave(index, jsonLoad(configGet("index", "locations")))
|
||||
logWrite(locale("cleanup_index_completed", "console", locale=configGet("locale")))
|
||||
logWrite(
|
||||
locale("cleanup_index_completed", "console", locale=configGet("locale"))
|
||||
)
|
||||
else:
|
||||
logWrite(locale("cleanup_index_unathorized", "console", locale=configGet("locale")))
|
||||
logWrite(
|
||||
locale("cleanup_index_unathorized", "console", locale=configGet("locale"))
|
||||
)
|
||||
|
||||
if args.norun:
|
||||
logWrite(locale("passed_norun", "console", locale=configGet("locale_log")))
|
||||
exit()
|
||||
#===========================================================================================================================================
|
||||
# ===========================================================================================================================================
|
||||
|
||||
|
||||
# Import ===================================================================================================================================
|
||||
@@ -73,7 +92,7 @@ try:
|
||||
except ModuleNotFoundError:
|
||||
print(locale("deps_missing", "console", locale=configGet("locale")), flush=True)
|
||||
exit()
|
||||
#===========================================================================================================================================
|
||||
# ===========================================================================================================================================
|
||||
|
||||
|
||||
pid = getpid()
|
||||
@@ -125,7 +144,7 @@ if configGet("submit", "mode"):
|
||||
|
||||
if configGet("api_based", "mode"):
|
||||
from modules.api_client import authorize
|
||||
#===========================================================================================================================================
|
||||
# ===========================================================================================================================================
|
||||
|
||||
# Work in progress
|
||||
# Handle new forwards
|
||||
@@ -168,25 +187,30 @@ if configGet("api_based", "mode"):
|
||||
# asyncio.run(main())
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
logWrite(locale("startup", "console", locale=configGet("locale")).format(str(pid)))
|
||||
|
||||
app.start()
|
||||
|
||||
|
||||
if configGet("startup", "reports"):
|
||||
app.send_message(app.owner, locale("startup", "message", locale=configGet("locale")).format(str(pid)))
|
||||
app.send_message(
|
||||
app.owner,
|
||||
locale("startup", "message", locale=configGet("locale")).format(str(pid)),
|
||||
)
|
||||
|
||||
if configGet("post", "mode"):
|
||||
scheduler.start()
|
||||
|
||||
#if configGet("api_based", "mode"):
|
||||
# if configGet("api_based", "mode"):
|
||||
# token = await authorize()
|
||||
# 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()
|
||||
|
||||
app.send_message(app.owner, locale("shutdown", "message", locale=configGet("locale")).format(str(pid)))
|
||||
app.send_message(
|
||||
app.owner,
|
||||
locale("shutdown", "message", locale=configGet("locale")).format(str(pid)),
|
||||
)
|
||||
logWrite(locale("shutdown", "console", locale=configGet("locale")).format(str(pid)))
|
||||
|
||||
killProc(pid)
|
||||
killProc(pid)
|
||||
|
Reference in New Issue
Block a user