018 019 020 zu mp3
This commit is contained in:
@@ -1,48 +1,87 @@
|
||||
import json
|
||||
import uuid
|
||||
import hashlib
|
||||
|
||||
with open('deck.json', 'r', encoding='utf-8') as f:
|
||||
|
||||
base91chars = (
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
|
||||
'0123456789!#$%&()*+,-./:;<=>?@[]^_`{|}~'
|
||||
)
|
||||
|
||||
def anki_guid(text: str) -> str:
|
||||
# SHA1-Hash des Front-Felds berechnen
|
||||
h = hashlib.sha1(text.encode('utf-8')).digest()
|
||||
x = int.from_bytes(h[:8], 'little') # Anki nimmt die ersten 8 Bytes, little-endian
|
||||
|
||||
# Kodierung in Base91-Zeichenkette (10 Zeichen)
|
||||
chars = []
|
||||
for _ in range(10):
|
||||
chars.append(base91chars[x % len(base91chars)])
|
||||
x //= len(base91chars)
|
||||
|
||||
return ''.join(chars)
|
||||
|
||||
with open('Schwedisch_Goetheverlag/deck.json', 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
|
||||
|
||||
original_notes = data['notes']
|
||||
new_notes = []
|
||||
existing_signatures = set()
|
||||
|
||||
def signature(front0, front1, back):
|
||||
return f"{front0}||{front1}||{back}"
|
||||
existing__notemodels = []
|
||||
for i in data['note_models']:
|
||||
existing__notemodels.append(i['crowdanki_uuid'])
|
||||
|
||||
for note in original_notes:
|
||||
fields = note['fields']
|
||||
note_model_uuid = note['note_model_uuid']
|
||||
if len(fields) < 3:
|
||||
continue
|
||||
|
||||
original_front = fields[0] # "ich"
|
||||
original_back = fields[1] # "jag"
|
||||
original_audio = fields[2] # "[sound:Jag-4718d0.mp3]"
|
||||
original_back_audio = fields[2] # "[sound:Jag-4718d0.mp3]"
|
||||
original_front_uuid = note_model_uuid
|
||||
new_uuid = None
|
||||
new_note = None
|
||||
|
||||
sig = signature(original_front, original_audio, original_back)
|
||||
reversed_sig = signature(original_back, original_audio, original_front)
|
||||
if original_front_uuid == existing__notemodels[0]:
|
||||
# Original:
|
||||
# Deutsch (Front)
|
||||
# Sverige (Back)
|
||||
# Audio (Backaudio)
|
||||
# Neu:
|
||||
# Sverige (Front)
|
||||
# Audio (Frontaudio)
|
||||
# Deutsch (Back)
|
||||
|
||||
if note['guid'].startswith('rev-') or reversed_sig in existing_signatures:
|
||||
continue
|
||||
new_note = {
|
||||
"__type__": "Note",
|
||||
"fields": [
|
||||
original_back,
|
||||
original_back_audio,
|
||||
original_front
|
||||
],
|
||||
"guid": f"{anki_guid(original_back)}",
|
||||
"note_model_uuid": existing__notemodels[1],
|
||||
"tags": []
|
||||
}
|
||||
new_notes.append(new_note)
|
||||
|
||||
new_note = {
|
||||
"__type__": "Note",
|
||||
"fields": [
|
||||
original_back, # Feld 0: Frage Text (Antwort aus Original)
|
||||
original_audio, # Feld 1: Frage Audio (MP3 aus Original)
|
||||
original_front # Feld 2: Antwort Text (Frage aus Original)
|
||||
],
|
||||
"guid": f"rev-{uuid.uuid4()}",
|
||||
"note_model_uuid": note["note_model_uuid"],
|
||||
"tags": note.get("tags", []) + ["reversed"]
|
||||
}
|
||||
# new_note = {
|
||||
# "__type__": "Note",
|
||||
# "fields": [
|
||||
# original_front,
|
||||
# original_front_audio,
|
||||
# original_back
|
||||
# ],
|
||||
# "guid": f"{anki_guid(original_front)}",
|
||||
# "note_model_uuid": note_model_uuid[1]
|
||||
# }
|
||||
# new_notes.append(new_note)
|
||||
# print(new_note
|
||||
|
||||
new_notes.append(new_note)
|
||||
existing_signatures.add(sig)
|
||||
existing_signatures.add(reversed_sig)
|
||||
|
||||
data['notes'].extend(new_notes)
|
||||
|
||||
with open('crowdanki_export_dupliziert.json', 'w', encoding='utf-8') as f:
|
||||
with open('Schwedisch_Goetheverlag/crowdanki_export_dupliziert.json', 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||
@@ -1,4 +1,4 @@
|
||||
import hashlib, uuid, random, string
|
||||
import hashlib, uuid, random, string, sys
|
||||
|
||||
def anki_guid1(text: str) -> str:
|
||||
#return hashlib.sha1(text.encode('utf-8')).hexdigest()[:10]
|
||||
@@ -35,4 +35,4 @@ def anki_guid(text: str) -> str:
|
||||
return ''.join(chars)
|
||||
|
||||
|
||||
print(anki_guid("ich und du"))
|
||||
print(anki_guid(sys.argv[1]))
|
||||
|
||||
Reference in New Issue
Block a user