This commit is contained in:
alzer
2025-05-15 21:36:04 +02:00
parent b327aa5c23
commit 0bcbc29f0f
8 changed files with 193 additions and 112 deletions
+1
View File
@@ -1,3 +1,4 @@
.history/
.idea/
compendium/To Do/Alte Übersetzung/Ganz alt/tmp.html
compendium/To Do/GPT/actors_split/
-11
View File
@@ -1,11 +0,0 @@
Fini :
F Cheminade -> Items UA1 -> DONE
Faytoto -> acteurs UA1
Dwim -> RNHD actors
Highcrown -> Acteurs Ennemi Ombre -> DONE
KeylaKhaine -> Acteurs Mort sur le Reik (27/03/24 fi)
Kyllian -> Acteurs Middenheim (15/05/24, fini)
Bobours -> Acteurs PBTT (15/05/24, fini)
Eltrys -> EiS
En cours :
-101
View File
@@ -1,101 +0,0 @@
import json
import sys
import os
def merge_entry(target, source, warn_ids):
sid = source.get("id", "unbekannt")
# Name ersetzen
new_name = source.get('name', target.get('name'))
target['name'] = new_name
# Beschreibung ergänzen
source_desc = source.get('description', '')
target_desc = target.get('description', '')
if source_desc and target_desc:
target['description'] = source_desc + "\n\n" + target_desc
elif source_desc:
target['description'] = source_desc
# Trappings ersetzen
if 'trappings' in source:
target['trappings'] = source['trappings']
# Effekte bearbeiten
source_effects = source.get('effects', [])
target_effects = target.get('effects', [])
# Labels in Ziel-Effekten ersetzen
if isinstance(target_effects, list):
for effect in target_effects:
if isinstance(effect, dict):
effect['label'] = new_name
else:
warn_ids.append(sid)
target_effects = []
# Neue Effekte anhängen
if isinstance(source_effects, list) and source_effects:
target_effects.extend(source_effects)
target['effects'] = target_effects
return target
def merge_files(target_file, source_files, output_file=None, new_ids_log="new_ids.txt", warn_log="warn_ids.txt"):
with open(target_file, "r", encoding="utf-8") as f:
target_json = json.load(f)
target_entries = target_json.get("entries", target_json)
target_by_id = {entry["id"]: entry for entry in target_entries}
new_ids = []
warn_ids = []
for source_path in source_files:
print(f"🔄 Verarbeite {source_path} ...")
with open(source_path, "r", encoding="utf-8") as f:
source_json = json.load(f)
source_entries = source_json.get("entries", source_json)
for source_entry in source_entries:
sid = source_entry.get("id")
if not sid:
print("⚠️ Eintrag ohne ID übersprungen.")
continue
if sid in target_by_id:
target_by_id[sid] = merge_entry(target_by_id[sid], source_entry, warn_ids)
else:
target_by_id[sid] = source_entry
new_ids.append(sid)
if "entries" in target_json:
target_json["entries"] = list(target_by_id.values())
final_output = target_json
else:
final_output = list(target_by_id.values())
with open(output_file or target_file, "w", encoding="utf-8") as f:
json.dump(final_output, f, indent=4, ensure_ascii=False)
if new_ids:
with open(new_ids_log, "w", encoding="utf-8") as f:
f.write("\n".join(new_ids))
print(f"🆕 {len(new_ids)} neue IDs siehe {new_ids_log}")
if warn_ids:
with open(warn_log, "w", encoding="utf-8") as f:
f.write("\n".join(warn_ids))
print(f"⚠️ {len(warn_ids)} Items mit ungültigen 'effects' siehe {warn_log}")
print(f"📁 Merge abgeschlossen → Datei überschrieben: {target_file}")
# Aufruf: python merge_items_with_effects_overwrite.py ziel.json quelle1.json [quelle2.json ...]
if __name__ == "__main__":
if len(sys.argv) < 3:
print("Nutzung: python merge_items_with_effects_overwrite.py ziel.json quelle1.json [quelle2.json ...]")
sys.exit(1)
target = sys.argv[1]
sources = sys.argv[2:]
merge_files(target, sources)
+100
View File
@@ -0,0 +1,100 @@
# -*- coding: utf-8 -*-
import os
import difflib
import chardet
import shutil
import urllib.parse
def normalize_line(line):
return line.strip()
def detect_encoding(file_path):
with open(file_path, "rb") as f:
raw_data = f.read()
result = chardet.detect(raw_data)
return result['encoding'] if result['encoding'] else 'utf-8'
def convert_to_utf8(file_path):
# Erkenne das aktuelle Encoding
encoding = detect_encoding(file_path)
if encoding.lower() == 'utf-8':
return file_path # Keine Konvertierung notwendig
# Konvertiere die Datei nach UTF-8
utf8_path = file_path + ".utf8"
with open(file_path, "rb") as f:
content = f.read().decode(encoding, errors="replace")
with open(utf8_path, "w", encoding="utf-8") as f:
f.write(content)
# Originaldatei löschen und umbenennen
print(f"Konvertiert: {file_path} ({encoding}) -> {utf8_path}")
os.remove(file_path)
shutil.move(utf8_path, file_path)
return file_path
def find_translated_files(original_folder, modified_folder, output_file):
original_files = {f for f in os.listdir(original_folder) if f.endswith(".js")}
modified_files = {f for f in os.listdir(modified_folder) if f.endswith(".js")}
common_files = original_files.intersection(modified_files)
translated_files = []
total_differences = 0
with open(output_file, "w", encoding="utf-8") as f:
for file_name in sorted(common_files):
original_path = os.path.abspath(os.path.join(original_folder, file_name))
modified_path = os.path.abspath(os.path.join(modified_folder, file_name))
# Dateien in UTF-8 konvertieren, falls notwendig
original_utf8 = convert_to_utf8(original_path)
modified_utf8 = convert_to_utf8(modified_path)
try:
with open(original_utf8, "r", encoding="utf-8") as orig_file, \
open(modified_utf8, "r", encoding="utf-8") as mod_file:
original_lines = [normalize_line(line) for line in orig_file if normalize_line(line)]
modified_lines = [normalize_line(line) for line in mod_file if normalize_line(line)]
diff = list(difflib.unified_diff(original_lines, modified_lines,
fromfile=original_path,
tofile=modified_path,
lineterm=""))
if diff:
num_changes = sum(1 for line in diff if line.startswith(("-", "+")) and not line.startswith(("---", "+++")))
translated_files.append((file_name, num_changes, original_path, modified_path))
total_differences += num_changes
# VS Code Diff Link erzeugen (absoluter Pfad, URL-enkodiert)
encoded_orig = urllib.parse.quote(original_path)
encoded_mod = urllib.parse.quote(modified_path)
vscode_diff_link = f"vscode://file/{encoded_orig}:0?diff={encoded_mod}:0"
# Header und Unterschiede in die Ausgabedatei schreiben
f.write(f"📝 Unterschiede in [{file_name}]({vscode_diff_link}) ({num_changes} Änderungen):\n")
f.write("\n".join(diff) + "\n\n")
except Exception as e:
print(f"Fehler beim Verarbeiten von {file_name}: {e}")
# Zusammenfassung am Ende der Datei hinzufügen (sortiert)
f.write("\n🔎 Zusammenfassung der Unterschiede (nach Anzahl der Änderungen sortiert):\n")
for file_name, count, orig_path, mod_path in sorted(translated_files, key=lambda x: x[1], reverse=True):
encoded_orig = urllib.parse.quote(orig_path)
encoded_mod = urllib.parse.quote(mod_path)
vscode_diff_link = f"vscode://file/{encoded_orig}:0?diff={encoded_mod}:0"
f.write(f"- [{file_name}]({vscode_diff_link}): {count} Änderungen\n")
f.write(f"\n📊 Gesamtanzahl der Änderungen: {total_differences}\n")
print(f"Prüfung abgeschlossen. {len(translated_files)} übersetzte Dateien gefunden.")
print(f"Ergebnis gespeichert in: {output_file}")
# Beispielpfade (kannst du anpassen)
original_folder = "original_scripts"
modified_folder = "modified_scripts"
output_file = "translated_files_with_direct_vscode_diff_links.md"
find_translated_files(original_folder, modified_folder, output_file)
+21
View File
@@ -0,0 +1,21 @@
import json
import os
# Verzeichnis mit den übersetzten Dateien
input_directory = "actors_split_translated"
output_file = "wfrp4e-eis-actors-merged.json"
# Alle übersetzten Dateien finden
merged_actors = {}
for file_name in os.listdir(input_directory):
if file_name.endswith(".json"):
file_path = os.path.join(input_directory, file_name)
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
merged_actors.update(data)
# Gesamte Datei speichern
with open(output_file, 'w', encoding='utf-8') as out_file:
json.dump(merged_actors, out_file, ensure_ascii=False, indent=4)
print(f"{len(merged_actors)} Einträge erfolgreich zusammengeführt.")
+23
View File
@@ -0,0 +1,23 @@
import json
import os
# Pfad zur Originaldatei
input_file = "wfrp4e-eis-actors-extracted.json"
output_directory = "actors_split"
# Stelle sicher, dass der Ausgabeordner existiert
os.makedirs(output_directory, exist_ok=True)
# Datei einlesen
with open(input_file, 'r', encoding='utf-8') as file:
data = json.load(file)
# Einträge einzeln speichern
for actor_id, actor_data in data.items():
# Dateiname erstellen
file_name = f"{output_directory}/{actor_id}.json"
# Einzeln speichern
with open(file_name, 'w', encoding='utf-8') as out_file:
json.dump({actor_id: actor_data}, out_file, ensure_ascii=False, indent=4)
print(f"Einträge in {len(data)} Dateien aufgeteilt.")
+48
View File
@@ -0,0 +1,48 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
import time
import os
# Verzeichnisse
input_directory = "actors_split"
download_directory = "actors_split_translated"
os.makedirs(download_directory, exist_ok=True)
# Geckodriver-Pfad (anpassen)
geckodriver_path = "/Pfad/zu/deinem/geckodriver"
# Firefox-Optionen
options = Options()
options.headless = False # Setze auf True, wenn du den Browser nicht sehen willst
# Webdriver starten
driver = webdriver.Firefox(executable_path=geckodriver_path, options=options)
# ChatGPT-Website öffnen
driver.get("https://chat.openai.com/")
# Warten, bis du dich eingeloggt hast
input("Bitte logge dich in ChatGPT ein und drücke dann Enter...")
# Dateien hochladen
for file_name in os.listdir(input_directory):
if file_name.endswith(".json"):
file_path = os.path.abspath(os.path.join(input_directory, file_name))
# Datei-Upload starten
upload_button = driver.find_element(By.XPATH, "//input[@type='file']")
upload_button.send_keys(file_path)
print(f"Datei hochgeladen: {file_name}")
# Warte auf die Antwort und download
time.sleep(20) # Wartezeit anpassen je nach Dateigröße
# Speichern der übersetzten Datei
with open(os.path.join(download_directory, file_name), 'w', encoding='utf-8') as out_file:
out_file.write(driver.page_source)
print(f"Übersetzte Datei gespeichert: {file_name}")
# Browser schließen
driver.quit()