105 lines
No EOL
3.5 KiB
Python
105 lines
No EOL
3.5 KiB
Python
import subprocess
|
|
import requests
|
|
import oead
|
|
import os
|
|
import xml.etree.ElementTree as ET
|
|
from config import settings, BASE_DIR
|
|
|
|
def process_boss_file():
|
|
temp_boss = "bosstemp.bin"
|
|
decrypt_script = os.path.join(BASE_DIR, "services", "decrypt.js")
|
|
|
|
if not os.path.exists(decrypt_script):
|
|
print(f"{decrypt_script} is missing!")
|
|
return False
|
|
|
|
base_url = settings.boss_url.rstrip('/')
|
|
tasks = [
|
|
{
|
|
"url": f"{base_url}/zvGSM4kOrXpkKnpT/schdat2?c=JP&l=en",
|
|
"filename": "VSSetting.byaml",
|
|
"output": "boss.yaml"
|
|
},
|
|
{
|
|
"url": f"{base_url}/zvGSM4kOrXpkKnpT/optdat2?c=US&l=en",
|
|
"filename": "Festival.byaml",
|
|
"output": "fes_boss.yaml"
|
|
}
|
|
]
|
|
|
|
try:
|
|
success_all = True
|
|
for task in tasks:
|
|
master_url = task["url"]
|
|
target_filename = task["filename"]
|
|
output_yaml = task["output"]
|
|
|
|
print(f"data get: {master_url}")
|
|
meta_res = requests.get(master_url, timeout=10)
|
|
meta_res.raise_for_status()
|
|
root = ET.fromstring(meta_res.content)
|
|
|
|
# LMFAO HOW DID THIS FLY UNDER THE RADAR FOR SO LONG
|
|
real_data_url = None
|
|
for file_element in root.findall(".//File"):
|
|
filename_elem = file_element.find("Filename")
|
|
if filename_elem is not None and filename_elem.text == target_filename:
|
|
url_elem = file_element.find("Url")
|
|
if url_elem is not None and url_elem.text:
|
|
real_data_url = url_elem.text.strip()
|
|
break
|
|
|
|
if not real_data_url:
|
|
print(f"woops! could not find URL for file '{target_filename}' in the XML response")
|
|
success_all = False
|
|
continue
|
|
|
|
print(f"parsed data url for {target_filename}: {real_data_url}")
|
|
res = requests.get(real_data_url, timeout=10)
|
|
res.raise_for_status()
|
|
|
|
with open(temp_boss, "wb") as f:
|
|
f.write(res.content)
|
|
|
|
node_env = os.environ.copy()
|
|
node_env["BOSS_AES_KEY"] = settings.boss_aes_key
|
|
node_env["BOSS_HMAC_KEY"] = settings.boss_hmac_key
|
|
|
|
result = subprocess.run(
|
|
['node', decrypt_script, temp_boss],
|
|
capture_output=True,
|
|
text=False,
|
|
env=node_env
|
|
)
|
|
|
|
if result.returncode != 0:
|
|
print(f"decrypt fail! {result.stderr.decode()}")
|
|
success_all = False
|
|
continue
|
|
|
|
byml_obj = oead.byml.from_binary(result.stdout)
|
|
yaml_content = oead.byml.to_text(byml_obj)
|
|
|
|
with open(output_yaml, "w", encoding="utf-8") as f:
|
|
f.write(yaml_content)
|
|
|
|
print(f"yay! success: {output_yaml}")
|
|
|
|
return success_all
|
|
|
|
except ET.ParseError:
|
|
print("woops! the url returned non xml... we're hanging here")
|
|
return False
|
|
except Exception as e:
|
|
print(f"exception {e}")
|
|
return False
|
|
|
|
finally:
|
|
print("garbage pickup is running (boss)")
|
|
if os.path.exists(temp_boss):
|
|
os.remove(temp_boss)
|
|
print(f"Removed {temp_boss}")
|
|
|
|
if os.path.exists("boss.byml"):
|
|
os.remove("boss.byml")
|
|
print("Removed boss.byml") |