Album check returned
This commit is contained in:
parent
cc6523f604
commit
af2bcd088f
37
poster.py
37
poster.py
@ -3,6 +3,7 @@ from os import getpid, path
|
||||
from sys import exit
|
||||
from time import time
|
||||
from traceback import format_exc
|
||||
from modules.api_client import authorize
|
||||
|
||||
from modules.cli import *
|
||||
from modules.http_client import http_session
|
||||
@ -207,10 +208,38 @@ async def main():
|
||||
if configGet("post", "mode"):
|
||||
scheduler.start()
|
||||
|
||||
# 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}"})
|
||||
try:
|
||||
|
||||
token = await authorize()
|
||||
|
||||
if (
|
||||
len(
|
||||
(
|
||||
await (
|
||||
await http_session.get(
|
||||
f'{configGet("address", "posting", "api")}/albums?q={configGet("queue", "posting", "api", "albums")}',
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
)
|
||||
).json()
|
||||
)["results"]
|
||||
)
|
||||
== 0
|
||||
):
|
||||
logWrite("Media album does not exist on API server. Trying to create it...")
|
||||
try:
|
||||
await http_session.post(
|
||||
f'{configGet("address", "posting", "api")}/albums?name={configGet("queue", "posting", "api", "albums")}&title={configGet("queue", "posting", "api", "albums")}',
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
)
|
||||
logWrite(
|
||||
"Created media album on API server."}"
|
||||
)
|
||||
except Exception as exp:
|
||||
logWrite(
|
||||
f"Could not create media album on API server due to {exp}: {format_exc()}"
|
||||
)
|
||||
except Exception as exp:
|
||||
logWrite(f"Could not check if API album exists due to {exp}: {format_exc()}")
|
||||
|
||||
await idle()
|
||||
|
||||
|
Reference in New Issue
Block a user