continued implementing caching in the sqlight db

This commit is contained in:
Lars Noack 2022-10-27 15:27:57 +02:00
parent 035a45b7d8
commit 0f0e605cf9
4 changed files with 29 additions and 9 deletions

0
sql.db
View File

View File

@ -73,7 +73,22 @@ def add_release_group(
connection.commit()
# add release group
query = "INSERT INTO release_group (id, albumartist, albumsort, musicbrainz_albumtype, compilation) VALUES (?, ?);"
query = "INSERT INTO release_group (id, albumartist, albumsort, musicbrainz_albumtype, compilation) VALUES (?, ?, ?, ?, ?);"
values = musicbrainz_releasegroupid, albumartist, albumsort, musicbrainz_albumtype, compilation
cursor.execute(query, values)
connection.commit()
def add_release(
musicbrainz_albumid: str,
release_group_id: str,
title: str = None,
copyright_: str = None
):
query = "INSERT INTO release_ (id, release_group_id, title, copyright) VALUES (?, ?, ?, ?);"
values = musicbrainz_albumid, release_group_id, title, copyright_
cursor.execute(query, values)
connection.commit()
if __name__ == "__main__":
pass

View File

@ -28,8 +28,9 @@ CREATE TABLE release_group (
DROP TABLE IF EXISTS release_;
CREATE TABLE release_ (
id TEXT PRIMARY KEY NOT NULL,
release_group TEXT NOT NULL,
name TEXT
release_group_id TEXT NOT NULL,
title TEXT,
copyright TEXT
);
DROP TABLE IF EXISTS track;

View File

@ -1,13 +1,9 @@
import imp
from typing import List
import musicbrainzngs
import pandas as pd
import logging
from datetime import date
import sqlite3
from object_handeling import get_elem_from_obj, parse_music_brainz_date
import database
@ -179,7 +175,7 @@ class Release:
self.title = get_elem_from_obj(release_data, ['title'])
self.copyright = get_elem_from_obj(label_data, [0, 'label', 'name'])
logging.info(f"release {self}")
self.save()
self.append_recordings(recording_datas)
def append_recordings(self, recording_datas: dict):
@ -190,6 +186,15 @@ class Release:
self.tracklist.append(musicbrainz_releasetrackid)
def save(self):
logging.info(f"release {self}")
database.add_release(
musicbrainz_albumid=self.musicbrainz_albumid,
release_group_id=self.release_group.musicbrainz_releasegroupid,
title=self.title,
copyright_=self.copyright
)
def __str__(self):
return f"{self.title} ©{self.copyright}"
@ -457,7 +462,6 @@ if __name__ == "__main__":
os.mkdir(TEMP_DIR)
"""
logging.basicConfig(level=logging.DEBUG)
sqliteConnection = sqlite3.connect('sql.db')
download({'id': '5cfecbe4-f600-45e5-9038-ce820eedf3d1', 'type': 'artist'})
# download({'id': '4b9af532-ef7e-42ab-8b26-c466327cb5e0', 'type': 'release'})