finalize metadata edit_database
asd
This commit is contained in:
1 parent
144d974731
commit
7c6a121504
1 file changed
+61
-10
+61
-10
@@ -39,6 +39,11 @@ def main():
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="Print data only",
|
help="Print data only",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--print-all",
|
||||||
|
action="store_true",
|
||||||
|
help="Print all data only",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"database",
|
"database",
|
||||||
type=Path,
|
type=Path,
|
||||||
@@ -56,9 +61,11 @@ def main():
|
|||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
|
|
||||||
list_genres = load_genre(cur,True)
|
list_genres = load_genre(cur,True)
|
||||||
|
if args.print_all:
|
||||||
|
for genre in list_genres:
|
||||||
|
print(genre)
|
||||||
|
return
|
||||||
|
|
||||||
#for genre in list_genres:
|
|
||||||
# print(genre)
|
|
||||||
rows = cur.execute(
|
rows = cur.execute(
|
||||||
"SELECT id, genres FROM books"
|
"SELECT id, genres FROM books"
|
||||||
).fetchall()
|
).fetchall()
|
||||||
@@ -67,34 +74,75 @@ def main():
|
|||||||
if not genres_json:
|
if not genres_json:
|
||||||
continue
|
continue
|
||||||
genres = json.loads(genres_json)
|
genres = json.loads(genres_json)
|
||||||
|
genres_new = []
|
||||||
new_genres = []
|
new_genres = []
|
||||||
print("=================================")
|
print("=================================")
|
||||||
print(f"Before sed: {genres}")
|
print(f"Before sed: {genres}")
|
||||||
for genre in genres:
|
for genre in genres:
|
||||||
|
if "Drachen" in genre:
|
||||||
|
pass
|
||||||
|
if "Fantastic" in genre:
|
||||||
|
pass
|
||||||
genre = re.sub(r'(?i)^audio\s*books?$', '', genre)
|
genre = re.sub(r'(?i)^audio\s*books?$', '', genre)
|
||||||
genre = re.sub(r'(?i)^audiobooks?$', '', genre)
|
genre = re.sub(r'(?i)^audiobooks?$', '', genre)
|
||||||
genre = re.sub(r'(?i)\bhörb(uch|ücher)\b', '', genre)
|
genre = re.sub(r'(?i)\b(hörb(uch|ücher)|hoerb(uch|uecher))\b', '', genre)
|
||||||
genre = re.sub(r'(?i)^(hörspiele?|hoerspiele?)$', '', genre)
|
genre = re.sub(r'(?i)^(hörspiele?|hoerspiele?)$', '', genre)
|
||||||
genre = re.sub(r'(?i)^spoken\s*word$', '', genre)
|
genre = re.sub(r'(?i)^spoken\s*word$', '', genre)
|
||||||
|
genre = re.sub(r'(?i)gesprochene\s*inhalte$', '', genre)
|
||||||
genre = re.sub(r'(?i)^speech$', '', genre)
|
genre = re.sub(r'(?i)^speech$', '', genre)
|
||||||
|
genre = re.sub(r'Fanasie', 'Fantasie', genre)
|
||||||
|
genre = re.sub(r'Mit Videospiel', 'Videospielbezug', genre)
|
||||||
|
genre = re.sub(r'(?i)nonfiction', 'NonFiction', genre)
|
||||||
|
|
||||||
|
genre = re.sub(r'(?i)^speech$', '', genre)
|
||||||
|
genre = re.sub(r'(?i)^vocal$', '', genre)
|
||||||
|
genre = re.sub(r'(?i)^retail$', '', genre)
|
||||||
|
genre = re.sub(r'(?i)^other$', '', genre)
|
||||||
|
genre = re.sub(r'(?i)^misc$', '', genre)
|
||||||
|
|
||||||
genre = re.sub(r'(?i)^(sci[- ]?fi|sf)$', 'Science Fiction', genre)
|
genre = re.sub(r'(?i)^(sci[- ]?fi|sf)$', 'Science Fiction', genre)
|
||||||
genre = re.sub(r'(?i)^nonfiction$', 'NonFiction', genre)
|
genre = re.sub(r'(?i)^\(?science fiction\)?$', 'Science Fiction', genre)
|
||||||
|
genre = re.sub(r'Thrillers', 'Thriller', genre)
|
||||||
|
genre = re.sub(r"(?i)\bchildren'?s audiobooks?\b", "",genre)
|
||||||
genre = re.sub(r'^-\s*|\s*-$', '', genre)
|
genre = re.sub(r'^-\s*|\s*-$', '', genre)
|
||||||
|
genre = re.sub(r'(?i)Engelske\s*\sLydbånd','',genre)
|
||||||
|
genre = re.sub(r'^FIC028000.*$', '', genre)
|
||||||
|
genre = re.sub(r'^800.*$', '', genre)
|
||||||
|
genre = re.sub(r'^Fantastic Beasts.*$', '', genre)
|
||||||
|
genre = re.sub(r'^and thei.*$', '', genre)
|
||||||
|
genre = re.sub(r'^those you.*$', '', genre)
|
||||||
genre = genre.strip()
|
genre = genre.strip()
|
||||||
|
genre = genre.lstrip()
|
||||||
|
|
||||||
new_genres.append(genre)
|
if "," in genre:
|
||||||
|
genre = genre.split(",")
|
||||||
|
elif " - " in genre:
|
||||||
|
genre = genre.split(" - ")
|
||||||
|
elif "Historical Adventure Thriller Mystery" in genre:
|
||||||
|
genre = genre.split(" ")
|
||||||
|
|
||||||
|
if isinstance(genre, str):
|
||||||
|
if len(genre) > 50 or (5 > len(genre) > 0):
|
||||||
|
genre = ""
|
||||||
|
print(f"Too long or too short: {genre}")
|
||||||
|
|
||||||
|
genre = genre.strip()
|
||||||
|
genre = genre.lstrip()
|
||||||
|
|
||||||
|
new_genres.append(genre)
|
||||||
|
elif isinstance(genre, list):
|
||||||
|
if len(genres) > 1:
|
||||||
|
genres = [g for g in genres if g]
|
||||||
|
new_genres.extend(genre)
|
||||||
|
|
||||||
new_genres = sorted(set(new_genres))
|
new_genres = sorted(set(new_genres))
|
||||||
|
|
||||||
print("Write to Database")
|
|
||||||
|
|
||||||
print(f"After sed: {new_genres}")
|
print(f"After sed: {new_genres}")
|
||||||
print("=================================")
|
|
||||||
|
|
||||||
list_difference = False
|
list_difference = False
|
||||||
|
print("Write to Database")
|
||||||
|
if len(new_genres) < len(genres):
|
||||||
|
list_difference = True
|
||||||
for old,new in zip(genres,new_genres):
|
for old,new in zip(genres,new_genres):
|
||||||
if old != new:
|
if old != new:
|
||||||
list_difference = True
|
list_difference = True
|
||||||
@@ -109,6 +157,9 @@ def main():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
print("Write to Database")
|
print("Write to Database")
|
||||||
|
|
||||||
|
|
||||||
|
print("=================================")
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"UPDATE books SET genres=? WHERE id=?",
|
"UPDATE books SET genres=? WHERE id=?",
|
||||||
(json.dumps(new_genres), book_id),
|
(json.dumps(new_genres), book_id),
|
||||||
Reference in new issue
Block a user