Browse Source

Mehrere Daten-Dateien, besserer Import

main
Adrian Heine 2 months ago
parent
commit
4068f47af9
  1. 23
      main.py

23
main.py

@ -4,15 +4,18 @@ import pyamf
import shutil import shutil
import json import json
import os import os
import glob
import argparse import argparse
import unicodedata import unicodedata
import random import random
import re import re
import sys import sys
import readline import readline
import datetime
DATA_DIR = os.environ.get('XDG_DATA_HOME', os.environ['HOME'] + '/.local/share') + '/klette' DATA_DIR = os.environ.get('XDG_DATA_HOME', os.environ['HOME'] + '/.local/share') + '/klette'
VOKABELN_FILE = DATA_DIR + '/vokabeln.json'
DEPRECATED_VOKABELN_FILE = DATA_DIR + '/vokabeln.json'
VOKABELN_DIR = DATA_DIR + '/vokabeln/'
STATUS_FILE = DATA_DIR + '/status.json' STATUS_FILE = DATA_DIR + '/status.json'
AUDIO_BASE = DATA_DIR + '/audio/' AUDIO_BASE = DATA_DIR + '/audio/'
@ -49,9 +52,10 @@ def import_vokabeln(file_name, audio_base):
'unidad': unidad, 'unidad': unidad,
'paso': paso 'paso': paso
}) })
if audio:
shutil.copy2(audio_base + audio + '.bin', shutil.copy2(audio_base + audio + '.bin',
AUDIO_BASE + audio + '.aac') AUDIO_BASE + audio + '.aac')
with open(VOKABELN_FILE, 'x') as writer:
with open(VOKABELN_DIR + '/import-' + datetime.datetime.now().isoformat() + '.json', 'x') as writer:
writer.write(json.dumps(palabras)) writer.write(json.dumps(palabras))
def import_status(file_name): def import_status(file_name):
@ -238,8 +242,16 @@ class Sesion:
def abfrage(parser, quiero_unidad, otra_vez): def abfrage(parser, quiero_unidad, otra_vez):
random.seed() random.seed()
try: try:
with open(VOKABELN_FILE, 'r') as f:
palabras = json.load(f)
palabras = []
os.makedirs(VOKABELN_DIR, exist_ok=True)
try:
os.rename(DEPRECATED_VOKABELN_FILE, os.path.join(VOKABELN_DIR, 'vokabeln.json'))
except FileNotFoundError:
pass
for filename in glob.glob(os.path.join(VOKABELN_DIR, '*.json')):
with open(filename, 'r') as f:
palabras += json.load(f)
with open(STATUS_FILE, 'r') as f: with open(STATUS_FILE, 'r') as f:
status = json.load(f) status = json.load(f)
except FileNotFoundError: except FileNotFoundError:
@ -255,7 +267,6 @@ def abfrage(parser, quiero_unidad, otra_vez):
print(f'{bcolors.OKGREEN}+{sesion.bien}{bcolors.ENDC} / {bcolors.FAIL}-{sesion.mal}{bcolors.ENDC}') print(f'{bcolors.OKGREEN}+{sesion.bien}{bcolors.ENDC} / {bcolors.FAIL}-{sesion.mal}{bcolors.ENDC}')
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
default_data_file = os.environ['PWD'] + '/assets/amf/vokabelTrainer147.amf'
parser.add_argument('--import-data', type=str, help="Path to assets", metavar="DIR") parser.add_argument('--import-data', type=str, help="Path to assets", metavar="DIR")
default_status_file = os.environ['HOME'] + '/klett/1266/vokabeltrainerData147' default_status_file = os.environ['HOME'] + '/klett/1266/vokabeltrainerData147'
parser.add_argument('--import-status', type=str, help="Path to AMF File, defaults to " + default_status_file, metavar="FILE", nargs='?', const=default_status_file) parser.add_argument('--import-status', type=str, help="Path to AMF File, defaults to " + default_status_file, metavar="FILE", nargs='?', const=default_status_file)
@ -264,7 +275,7 @@ parser.add_argument('--otra-vez', action='store_true')
args = parser.parse_args() args = parser.parse_args()
if args.import_data: if args.import_data:
import_vokabeln(args.import_data + '/amf/vokabelTrainer147.amf',
import_vokabeln(glob.glob(os.path.join(args.import_data, 'amf/vokabelTrainer*.amf'))[0],
args.import_data + '/amf/medium/') args.import_data + '/amf/medium/')
elif args.import_status: elif args.import_status:
import_status(args.import_status) import_status(args.import_status)

Loading…
Cancel
Save