#!/usr/bin/env python3 """ TinyTag autocasts the tracknumber and discnumber tags to ints, which I fixed by re-casting them to strs. I forgot to include the zeropadding when I did that. This script fixes that in the database. """ import asyncio import asyncpg import config async def fix_zpad(): db_pool = await asyncpg.create_pool(**config.db) async with db_pool.acquire() as conn: tracks = await conn.fetch("SELECT filepath, tracknumber FROM track") data = [(t['filepath'], t['tracknumber'].zfill(2)) for t in tracks] stmt = await conn.prepare("UPDATE track SET tracknumber = $2 WHERE filepath = $1") await stmt.executemany(data) print("Done.") if __name__ == '__main__': asyncio.run(fix_zpad())