WIP: API change

This commit is contained in:
2023-03-23 15:03:30 +01:00
parent c948f2e34d
commit 2d0d72b026
6 changed files with 168 additions and 59 deletions

View File

@@ -3,7 +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.api_client import authorize, album_find, album_create
from modules.cli import *
from modules.http_client import http_session
@@ -106,8 +106,8 @@ if configGet("post", "mode"):
# if configGet("api_based", "mode"):
# token = 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}"})
# if len(get(f'{configGet("address", "posting", "api")}/albums?q={configGet("album", "posting", "api")}', headers={"Authorization": f"Bearer {token}"}).json()["results"]) == 0:
# post(f'{configGet("address", "posting", "api")}/albums?name={configGet("album", "posting", "api")}&title={configGet("album", "posting", "api")}', headers={"Authorization": f"Bearer {token}"})
# await idle()
@@ -209,31 +209,24 @@ async def main():
scheduler.start()
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"]
await album_find(
client=client, q=configGet("album", "posting", "api")
)
).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."}"
await album_create(
client=client,
name=configGet("album", "posting", "api"),
title=configGet("album", "posting", "api"),
)
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()}"