This commit is contained in:
alzer
2025-05-16 13:57:05 +02:00
5 changed files with 186 additions and 20 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
}
],
"url": "https://gitea.palmenalzer.de/alzer/wfrp-4e-de",
"version": "8.5.19",
"version": "8.5.20",
"esmodules": [
"modules/babele-register.js",
"modules/addon-register.js",
File diff suppressed because one or more lines are too long
+160
View File
@@ -0,0 +1,160 @@
import os
import json
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
# Verzeichnisse
input_file = "wfrp4e-eis-actors-extracted.json"
split_directory = "actors_split"
translated_directory = "actors_split_translated"
merged_file_path = "wfrp4e-eis-actors-merged.json"
os.makedirs(split_directory, exist_ok=True)
os.makedirs(translated_directory, exist_ok=True)
# Pfad zu deinem Chrome Profil (anpassen)
chrome_profile_path = "C:/Users/Alzer/AppData/Local/Google/Chrome/User Data/Default/"
# Deine Chat-URL (ersetzen)
chat_url = "https://chatgpt.com/c/68271195-7a84-800d-b66a-7a73edfb121a" # Deine echte Chat-URL hier einfügen
# Geckodriver-Pfad (anpassen, falls nötig)
chromedriver_path = "C:/Windows/System32/chromedriver.exe"
cookie_file = "chrome_cookies.json"
# Schritt 1: Datei in Einträge aufteilen
try:
with open(input_file, 'r', encoding='utf-8') as file:
data = json.load(file)
print(f"{len(data)} Einträge gefunden. Aufteilen der Datei...")
for actor_id, actor_data in data.items():
# Eintrag speichern
split_file_path = os.path.join(split_directory, f"{actor_id}.json")
with open(split_file_path, 'w', encoding='utf-8') as split_file:
json.dump({actor_id: actor_data}, split_file, ensure_ascii=False, indent=4)
print(f"Datei in {len(data)} Einträge aufgeteilt.")
except FileNotFoundError as e:
print(f"Fehler beim Laden der Datei: {e}")
exit(1)
except json.JSONDecodeError as e:
print(f"Fehler beim Dekodieren der JSON-Datei: {e}")
exit(1)
# Schritt 2: Automatisierter Upload und Download
try:
# Chrome-Optionen
options = Options()
options.add_argument(f"--user-data-dir={chrome_profile_path}")
options.add_argument("--profile-directory=Default")
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.headless = False # Setze auf True, wenn du den Browser nicht sehen willst
# Webdriver starten
service = Service(chromedriver_path)
driver = webdriver.Chrome(service=service, options=options)
driver.get("https://chat.openai.com/")
# Cookies importieren, falls vorhanden
if os.path.exists(cookie_file):
with open(cookie_file, "r") as file:
cookies = json.load(file)
for cookie in cookies:
# Cookie-Domain korrigieren
if "domain" in cookie:
cookie["domain"] = ".chat.openai.com"
try:
driver.add_cookie(cookie)
except Exception as e:
print(f"⚠️ Fehler beim Setzen des Cookies: {e}")
print("✅ Cookies importiert.")
# Seite neu laden, um Cookies zu aktivieren
driver.get("https://chat.openai.com/")
# Cookies speichern (nur beim ersten Mal notwendig)
if not os.path.exists(cookie_file):
# Warten, bis du dich eingeloggt hast
input("🔑 Bitte logge dich ein und drücke dann Enter, wenn du bereit bist...")
with open(cookie_file, "w") as file:
cookies = driver.get_cookies()
for cookie in cookies:
if "domain" in cookie:
cookie["domain"] = ".chat.openai.com"
json.dump(cookies, file)
print("✅ Cookies gespeichert.")
# Warten, bis du dich eingeloggt hast
input("🔑 Bitte logge dich ein und drücke dann Enter, wenn du bereit bist...")
translated_entries = {}
for file_name in os.listdir(split_directory):
if file_name.endswith(".json"):
file_path = os.path.abspath(os.path.join(split_directory, file_name))
try:
# 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 Verarbeitung (anpassen je nach Dateigröße)
time.sleep(30)
# Übersetzten Inhalt extrahieren
translated_text = driver.page_source
# Datei speichern
translated_file_path = os.path.join(translated_directory, file_name)
with open(translated_file_path, 'w', encoding='utf-8') as out_file:
out_file.write(translated_text)
print(f"✅ Übersetzte Datei gespeichert: {file_name}")
# Eintrag zum zusammenführen vorbereiten
with open(translated_file_path, 'r', encoding='utf-8') as translated_file:
try:
translated_entry = json.load(translated_file)
translated_entries.update(translated_entry)
except json.JSONDecodeError as e:
print(f"❌ Fehler beim Laden der Datei {file_name}: {e}")
except Exception as e:
print(f"❌ Fehler beim Datei-Upload: {e}")
except Exception as e:
print(f"❌ Fehler beim Starten des Chrome-Browsers: {e}")
exit(1)
finally:
# Browser schließen, auch bei Fehlern
try:
driver.quit()
print("✅ Browser geschlossen.")
except NameError:
print("⚠️ Kein aktiver Browser gefunden.")
# Schritt 3: Validierung und Zusammenführung
print("🔍 Überprüfe und zusammenführe die übersetzten Einträge...")
valid_entries = {}
for entry_id, entry_data in translated_entries.items():
try:
# Überprüfung der JSON-Integrität
json.dumps(entry_data)
valid_entries[entry_id] = entry_data
except (TypeError, ValueError) as e:
print(f"❌ Ungültiger Eintrag ({entry_id}): {e}")
# Gesamte Datei zusammenführen und speichern
with open(merged_file_path, 'w', encoding='utf-8') as merged_file:
json.dump(valid_entries, merged_file, ensure_ascii=False, indent=4)
print(f"✅ Zusammengeführte Datei gespeichert: {merged_file_path}")
+17 -10
View File
@@ -1,21 +1,28 @@
import fs from "fs";
import path from "path";
let path = "./scripts/"
let scripts = fs.readdirSync(path);
let basePath = "./scripts/";
let scripts = fs.readdirSync(basePath);
let count = 0;
let scriptObj = {};
for(let file of scripts)
{
let script = fs.readFileSync(path + file, {encoding:"utf8"});
scriptObj[file.split(".")[0]] = script;
count++;
for (let file of scripts) {
let fullPath = path.join(basePath, file);
// Ignoriere Verzeichnisse
if (fs.lstatSync(fullPath).isDirectory()) {
continue;
}
let script = fs.readFileSync(fullPath, { encoding: "utf8" });
scriptObj[file.split(".")[0]] = script;
count++;
}
let scriptLoader = `export default function()
{
mergeObject(game.wfrp4e.config.effectScripts, ${JSON.stringify(scriptObj)});
}`
fs.writeFileSync("./modules/loadScripts.js", scriptLoader)
console.log(`Packed ${count} scripts`);
fs.writeFileSync("./modules/loadScripts.js", scriptLoader);
console.log(`Packed ${count} scripts`);
+7 -7
View File
@@ -1,4 +1,4 @@
if (!this.item.name.includes("(") || this.item.system.tests.value.includes("(Sense)"))
if (!this.item.name.includes("(") || this.item.system.tests.value.includes("(Sinn)"))
{
let tests = this.item.system.tests.value
let name = this.item.name
@@ -12,12 +12,12 @@ if (!this.item.name.includes("(") || this.item.system.tests.value.includes("(Sen
else // If no sense specified, provide dialog choice
{
let choice = await ItemDialog.create(ItemDialog.objectToArray({
taste : "Taste",
sight : "Sight",
smell : "Smell",
hearing : "Hearing",
touch : "Touch"
}, this.item.img), 1, "Choose Sense");
taste : "Geschmack",
sight : "Sicht",
smell : "Geruch",
hearing : "Gehör",
touch : "Berührung"
}, this.item.img), 1, "Wähle Sinn");
if (choice[0])
{
name = `${name.split("(")[0].trim()} (${choice[0].name})`