add log to audiobooks edit database
asd
This commit is contained in:
1 parent
9e4901699d
commit
144d974731
1 file changed
+33
-9
@@ -57,39 +57,63 @@ def main():
|
||||
|
||||
list_genres = load_genre(cur,True)
|
||||
|
||||
for genre in list_genres:
|
||||
print(genre)
|
||||
for book_id, genres_json in cur.execute("SELECT id, genres FROM books"):
|
||||
#for genre in list_genres:
|
||||
# print(genre)
|
||||
rows = cur.execute(
|
||||
"SELECT id, genres FROM books"
|
||||
).fetchall()
|
||||
|
||||
for book_id, genres_json in rows:
|
||||
if not genres_json:
|
||||
continue
|
||||
|
||||
genres = json.loads(genres_json)
|
||||
new_genres = []
|
||||
|
||||
print("=================================")
|
||||
print(f"Before sed: {genres}")
|
||||
for genre in genres:
|
||||
genre = re.sub(r'(?i)^audio\s*books?$', '', genre)
|
||||
genre = re.sub(r'(?i)^audiobooks?$', '', genre)
|
||||
genre = re.sub(r'(?i)^hörb(uch|ücher)$', '', genre)
|
||||
genre = re.sub(r'(?i)^hörspiele?$', '', genre)
|
||||
genre = re.sub(r'(?i)\bhörb(uch|ücher)\b', '', genre)
|
||||
genre = re.sub(r'(?i)^(hörspiele?|hoerspiele?)$', '', genre)
|
||||
genre = re.sub(r'(?i)^spoken\s*word$', '', genre)
|
||||
genre = re.sub(r'(?i)^speech$', '', genre)
|
||||
|
||||
genre = re.sub(r'(?i)^(sci[- ]?fi|sf)$', 'Science Fiction', genre)
|
||||
genre = re.sub(r'(?i)^nonfiction$', 'NonFiction', genre)
|
||||
|
||||
genre = re.sub(r'^-\s*|\s*-$', '', genre)
|
||||
genre = genre.strip()
|
||||
|
||||
if genre:
|
||||
new_genres.append(genre)
|
||||
new_genres.append(genre)
|
||||
|
||||
new_genres = sorted(set(new_genres))
|
||||
|
||||
print("Write to Database")
|
||||
|
||||
print(f"After sed: {new_genres}")
|
||||
print("=================================")
|
||||
|
||||
list_difference = False
|
||||
|
||||
for old,new in zip(genres,new_genres):
|
||||
if old != new:
|
||||
list_difference = True
|
||||
break
|
||||
|
||||
if not list_difference:
|
||||
print("No difference: Dont Commit to Database")
|
||||
continue
|
||||
|
||||
if args.print_only:
|
||||
print("Print only: Dont Commit to database")
|
||||
continue
|
||||
|
||||
print("Write to Database")
|
||||
cur.execute(
|
||||
"UPDATE books SET genres=? WHERE id=?",
|
||||
(json.dumps(new_genres), book_id),
|
||||
)
|
||||
print("Database Updated")
|
||||
|
||||
db.commit()
|
||||
|
||||
|
||||
Reference in new issue
Block a user