CoolFace
Apppublic

kaan1233/bistelligence-api

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes
split_app.py58 linesDownload Raw Back to root
1import re2import os3 4app_path = "frontend/app.js"5js_dir = "frontend/js"6if not os.path.exists(js_dir):7    os.makedirs(js_dir)8 9with open(app_path, "r", encoding="utf-8") as f:10    content = f.read()11 12# Define the sections13sections = re.split(r'(?=(?:^|\n)// ==================== .*? ====================)', content)14 15files_map = {16    "auth.js": ["Firebase Setup", "Firebase Auth Logic", "LOGOUT"],17    "api.js": ["API", "Formatters"],18    "dashboard.js": ["HOME PAGE", "SECTORS", "AI MODEL PORTFOLIO", "SCREENER", "BACKTEST", "ALGORITHM SETTINGS"],19    "portfolio.js": ["PORTFOLIO", "WATCHLIST", "Forms"],20    "ui.js": ["Navigation", "THEME TOGGLE", "Init", "STOCK DETAIL MODAL"]21}22 23existing_ui = ""24if os.path.exists("frontend/js/ui.js"):25    with open("frontend/js/ui.js", "r", encoding="utf-8") as f:26        existing_ui = f.read()27 28file_contents = {k: "" for k in files_map.keys()}29file_contents["ui.js"] = existing_ui + "\n"30 31for section in sections:32    if not section.strip(): continue33    match = re.search(r'// ==================== (.*?) ====================', section)34    if match:35        name = match.group(1).strip()36        # Find which file it belongs to37        found = False38        for fname, names in files_map.items():39            if name in names:40                file_contents[fname] += "\n" + section.strip() + "\n"41                found = True42                break43        if not found:44            # default to main.js45            if "main.js" not in file_contents:46                file_contents["main.js"] = ""47            file_contents["main.js"] += "\n" + section.strip() + "\n"48    else:49        file_contents["api.js"] = section.strip() + "\n" + file_contents["api.js"]50 51for fname, data in file_contents.items():52    if data.strip():53        with open(os.path.join(js_dir, fname), "w", encoding="utf-8") as f:54            f.write(data)55 56os.rename(app_path, app_path + ".backup")57print("Splitting complete. Backup saved as app.js.backup")58