dev #19
37
poster.py
37
poster.py
@ -3,6 +3,7 @@ from os import getpid, path
|
|||||||
from sys import exit
|
from sys import exit
|
||||||
from time import time
|
from time import time
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
|
from modules.api_client import authorize
|
||||||
|
|
||||||
from modules.cli import *
|
from modules.cli import *
|
||||||
from modules.http_client import http_session
|
from modules.http_client import http_session
|
||||||
@ -207,10 +208,38 @@ async def main():
|
|||||||
if configGet("post", "mode"):
|
if configGet("post", "mode"):
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
|
|
||||||
# if configGet("api_based", "mode"):
|
try:
|
||||||
# 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:
|
token = await authorize()
|
||||||
# post(f'{configGet("address", "posting", "api")}/albums?name={configGet("queue", "posting", "api", "albums")}&title={configGet("queue", "posting", "api", "albums")}', headers={"Authorization": f"Bearer {token}"})
|
|
||||||
|
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()
|
await idle()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user