mirror of
https://github.com/283375/arcaea-offline.git
synced 2025-04-19 06:00:18 +00:00
feat(external): supporting chart info database
This commit is contained in:
parent
54749c8df2
commit
2bd64bbd5e
1
src/arcaea_offline/external/chart_info_db/__init__.py
vendored
Normal file
1
src/arcaea_offline/external/chart_info_db/__init__.py
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .parser import ChartInfoDbParser
|
35
src/arcaea_offline/external/chart_info_db/parser.py
vendored
Normal file
35
src/arcaea_offline/external/chart_info_db/parser.py
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import contextlib
|
||||||
|
import sqlite3
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from ...models.songs import ChartInfo
|
||||||
|
|
||||||
|
|
||||||
|
class ChartInfoDbParser:
|
||||||
|
def __init__(self, filepath):
|
||||||
|
self.filepath = filepath
|
||||||
|
|
||||||
|
def parse(self) -> List[ChartInfo]:
|
||||||
|
results = []
|
||||||
|
with sqlite3.connect(self.filepath) as conn:
|
||||||
|
with contextlib.closing(conn.cursor()) as cursor:
|
||||||
|
db_results = cursor.execute(
|
||||||
|
"SELECT song_id, rating_class, constant, notes FROM charts_info"
|
||||||
|
).fetchall()
|
||||||
|
for result in db_results:
|
||||||
|
chart = ChartInfo(
|
||||||
|
song_id=result[0],
|
||||||
|
rating_class=result[1],
|
||||||
|
constant=result[2],
|
||||||
|
notes=result[3] or None,
|
||||||
|
)
|
||||||
|
results.append(chart)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
def write_database(self, session: Session):
|
||||||
|
results = self.parse()
|
||||||
|
for result in results:
|
||||||
|
session.merge(result)
|
Loading…
x
Reference in New Issue
Block a user