es können nun mehrere Ausgabeformate bei der Extraktion auf einmal angegeben werden, z.B. text,json,excel
This commit is contained in:
+50
-33
@@ -1154,8 +1154,7 @@ if __name__ == '__main__':
|
|||||||
'-t', '--export-type',
|
'-t', '--export-type',
|
||||||
action='store',
|
action='store',
|
||||||
default='json',
|
default='json',
|
||||||
choices=['excel', 'json', 'text'],
|
help='Exportformat(e): json (Standard), excel, text oder komma-separiert (z.B. excel,json,text)'
|
||||||
help='Exportformat: json (Standard), excel (Excel-Datei) oder text (Textdatei mit Abschnitten)'
|
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--translate',
|
'--translate',
|
||||||
@@ -1179,6 +1178,19 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Parse und validiere Export-Typen (komma-separierte Liste)
|
||||||
|
valid_export_types = {'excel', 'json', 'text'}
|
||||||
|
export_types = [t.strip() for t in args.export_type.split(',')]
|
||||||
|
|
||||||
|
# Validiere jeden Export-Typ
|
||||||
|
for export_type in export_types:
|
||||||
|
if export_type not in valid_export_types:
|
||||||
|
parser.error(f"Ungültiger Export-Typ: '{export_type}'. Erlaubt sind: {', '.join(sorted(valid_export_types))}")
|
||||||
|
|
||||||
|
# Entferne Duplikate und behalte Reihenfolge
|
||||||
|
seen = set()
|
||||||
|
export_types = [t for t in export_types if not (t in seen or seen.add(t))]
|
||||||
|
|
||||||
# Validierung: --extract benötigt --filename
|
# Validierung: --extract benötigt --filename
|
||||||
if args.extract and not args.filename:
|
if args.extract and not args.filename:
|
||||||
parser.error("--extract benötigt --filename")
|
parser.error("--extract benötigt --filename")
|
||||||
@@ -1371,37 +1383,42 @@ if __name__ == '__main__':
|
|||||||
# Schritt 2: Texte filtern
|
# Schritt 2: Texte filtern
|
||||||
texts, ignored_texts = filter_texts(all_texts, wildcard_patterns, regex_patterns, args.debug)
|
texts, ignored_texts = filter_texts(all_texts, wildcard_patterns, regex_patterns, args.debug)
|
||||||
|
|
||||||
# Erstelle Output-Dateinamen basierend auf Export-Typ
|
# Mapping für Dateiendungen
|
||||||
if args.outname:
|
extension_map = {
|
||||||
# Verwende benutzerdefinierten Namen
|
'excel': '.xlsx',
|
||||||
output_filename = args.outname
|
'json': '.json',
|
||||||
# Füge Endung hinzu falls nicht vorhanden
|
'text': '.txt'
|
||||||
if args.export_type == 'excel':
|
}
|
||||||
if not output_filename.endswith('.xlsx'):
|
|
||||||
output_filename += '.xlsx'
|
# Export für jeden angegebenen Typ durchführen
|
||||||
elif args.export_type == 'json':
|
print(f"\nExportiere in {len(export_types)} Format(e): {', '.join(export_types)}")
|
||||||
if not output_filename.endswith('.json'):
|
|
||||||
output_filename += '.json'
|
for export_type in export_types:
|
||||||
|
# Erstelle Output-Dateinamen basierend auf Export-Typ
|
||||||
|
if args.outname:
|
||||||
|
# Verwende benutzerdefinierten Namen
|
||||||
|
base_name = args.outname
|
||||||
|
# Entferne existierende Endung falls vorhanden
|
||||||
|
for ext in extension_map.values():
|
||||||
|
if base_name.endswith(ext):
|
||||||
|
base_name = base_name[:-len(ext)]
|
||||||
|
break
|
||||||
|
# Füge korrekte Endung hinzu
|
||||||
|
output_filename = f"{base_name}{extension_map[export_type]}"
|
||||||
|
else:
|
||||||
|
# Standardname basierend auf Eingabedatei
|
||||||
|
output_filename = f"{filename.stem}_texts{extension_map[export_type]}"
|
||||||
|
|
||||||
|
output_path = work_dir / output_filename
|
||||||
|
|
||||||
|
# Schreibe Texte in gewähltem Format
|
||||||
|
if export_type == 'excel':
|
||||||
|
write_texts_to_excel(texts, output_path, translation_dicts)
|
||||||
|
elif export_type == 'json':
|
||||||
|
write_texts_to_json(texts, ignored_texts, output_path, translation_dicts)
|
||||||
else: # text
|
else: # text
|
||||||
if not output_filename.endswith('.txt'):
|
write_texts_to_text(texts, ignored_texts, output_path, translation_dicts)
|
||||||
output_filename += '.txt'
|
|
||||||
else:
|
|
||||||
# Standardname basierend auf Eingabedatei
|
|
||||||
if args.export_type == 'excel':
|
|
||||||
output_filename = filename.stem + "_texts.xlsx"
|
|
||||||
elif args.export_type == 'json':
|
|
||||||
output_filename = filename.stem + "_texts.json"
|
|
||||||
else: # text
|
|
||||||
output_filename = filename.stem + "_texts.txt"
|
|
||||||
|
|
||||||
output_path = work_dir / output_filename
|
print(f" [OK] {export_type}: {output_path}")
|
||||||
|
|
||||||
# Schreibe Texte in gewähltem Format
|
print("\nVerarbeitung erfolgreich abgeschlossen.")
|
||||||
if args.export_type == 'excel':
|
|
||||||
write_texts_to_excel(texts, output_path, translation_dicts)
|
|
||||||
elif args.export_type == 'json':
|
|
||||||
write_texts_to_json(texts, ignored_texts, output_path, translation_dicts)
|
|
||||||
else: # text
|
|
||||||
write_texts_to_text(texts, ignored_texts, output_path, translation_dicts)
|
|
||||||
|
|
||||||
print("Verarbeitung erfolgreich abgeschlossen.")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user