Command Line

A small CLI is bundled with the library, designed to reduce boilerplate when writing scripts. It helps you quickly initialize a working directory and generate script files from predefined templates. The CLI is made with typer.

init

Initialize a directory for writing scripts.

Usage

amqcsl init [dir]

Description

  • dir Path to the directory to initialize, defaults to cwd

This command creates directories log/, logs/, scripts/, and files .env and .gitignore. The user will be prompted with credentials to fill out the env file. If there is an existing directory called log/, the command will terminate early. For the files, data will be appended if the files already exist, and added to a new file if it doesn’t.

make

Create a new script from a template.

amqcsl make [-t] [dest]

Description

  • dest Path for the destination file, required

  • -t/--template The file template to generate, defaults to simple. See below for available templates.

Default Sync
import logging
import os

from dotenv import load_dotenv
from log import setup_logging
from rich.pretty import pprint

import amqcsl

_ = load_dotenv()


def main(logger: logging.Logger):
    with amqcsl.DBClient(
        username=os.getenv('AMQ_USERNAME'),
        password=os.getenv('AMQ_PASSWORD'),
    ) as client:
        pprint('shiHib')


if __name__ == '__main__':
    logger = logging.getLogger('TEMPLATE_SCRIPT_NAME')
    setup_logging()
    main(logger)
Character
import asyncio
import logging
import os

import amqcsl
from amqcsl.objects import CSLTrack
from amqcsl.workflows import character as cm
from dotenv import load_dotenv

from log import setup_logging

_ = load_dotenv()

characters: cm.CharacterDict = {}

artists: cm.ArtistDict = {}


async def main(logger: logging.Logger):
    async with amqcsl.AsyncDBClient(
        username=os.getenv('AMQ_USERNAME'),
        password=os.getenv('AMQ_PASSWORD'),
    ) as client:
        artist_to_meta = await cm.make_artist_to_meta(
            client,
            characters,
            artists,
            [],
        )
        my_group = client.groups['INSERT GROUP NAME HERE']
        tracks = client.iter_tracks(groups=[my_group], batch_size=100)
        async with asyncio.TaskGroup() as tg:
            _ = [tg.create_task(process_track(client, track, artist_to_meta)) async for track in tracks]

        if cm.prompt(client.queue):
            await client.commit()


async def process_track(
    client: amqcsl.AsyncDBClient,
    track: CSLTrack,
    artist_to_meta: cm.ArtistToMeta,
) -> None:
    meta = await client.get_metadata(track)
    cm.queue_character_metadata(client, track, artist_to_meta, meta)


if __name__ == '__main__':
    logger = logging.getLogger('TEMPLATE_SCRIPT_NAME')
    setup_logging()
    asyncio.run(main(logger))
Compact Character
import asyncio
import logging
import os

import amqcsl
from amqcsl.objects import CSLTrack
from amqcsl.workflows import character as cm
from dotenv import load_dotenv

from log import setup_logging

_ = load_dotenv()

artists: cm.ArtistDict = {}


async def main(logger: logging.Logger):
    async with amqcsl.AsyncDBClient(
        username=os.getenv('AMQ_USERNAME'),
        password=os.getenv('AMQ_PASSWORD'),
    ) as client:
        artist_to_meta = await cm.compact_make_artist_to_meta(
            client,
            artists,
            [],
        )
        my_group = client.groups['INSERT GROUP NAME HERE']
        tracks = client.iter_tracks(groups=[my_group], batch_size=100)
        async with asyncio.TaskGroup() as tg:
            _ = [tg.create_task(process_track(client, track, artist_to_meta)) async for track in tracks]

        if cm.prompt(client.queue):
            await client.commit()


async def process_track(
    client: amqcsl.AsyncDBClient,
    track: CSLTrack,
    artist_to_meta: cm.ArtistToMeta,
) -> None:
    meta = await client.get_metadata(track)
    cm.queue_character_metadata(client, track, artist_to_meta, meta)


if __name__ == '__main__':
    logger = logging.getLogger('TEMPLATE_SCRIPT_NAME')
    setup_logging()
    asyncio.run(main(logger))
Default Async
import asyncio
import logging
import os

from dotenv import load_dotenv
from log import setup_logging
from rich.pretty import pprint

import amqcsl

_ = load_dotenv()


async def main(logger: logging.Logger):
    async with amqcsl.AsyncDBClient(
        username=os.getenv('AMQ_USERNAME'),
        password=os.getenv('AMQ_PASSWORD'),
    ) as client:
        pprint('shiHib')


if __name__ == '__main__':
    logger = logging.getLogger('TEMPLATE_SCRIPT_NAME')
    setup_logging()
    asyncio.run(main(logger))