Skip to content

Commit

Permalink
Add aliases from Tachi
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-psi committed Mar 17, 2024
1 parent 695d2dd commit d66a08f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions dbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ async def update_aliases(async_session: async_sessionmaker[AsyncSession]):
resp = await client.get(
"https://github.com/lomotos10/GCM-bot/raw/main/data/aliases/en/chuni.tsv"
)
tachi_resp = await client.get(
"https://github.com/TNG-dev/Tachi/raw/staging/database-seeds/collections/songs-chunithm.json"
)
aliases = [x.split("\t") for x in (await resp.text()).splitlines()]
tachi_songs = await tachi_resp.json(loads=json_loads)

inserted_aliases = []
for alias in aliases:
Expand All @@ -235,6 +239,23 @@ async def update_aliases(async_session: async_sessionmaker[AsyncSession]):
]
)

for tachi_song in tachi_songs:
song = (
await session.execute(
select(Song).where(Song.title == tachi_song["title"])
)
).scalar_one_or_none()

if song is None:
continue

inserted_aliases.extend(
[
{"alias": x, "guild_id": -1, "song_id": song.id, "owner_id": None}
for x in tachi_song["searchTerms"]
]
)

insert_statement = insert(Alias).values(inserted_aliases)
upsert_statement = insert_statement.on_conflict_do_update(
index_elements=[Alias.alias, Alias.guild_id],
Expand Down

0 comments on commit d66a08f

Please sign in to comment.