DJ-Goanna-Coding/oppo-node
0
1"""2APPS SCRIPT TOOLBOX3Links citadel_reporter.py and citadel_archivist.py to Google Sheets4 5This script acts as the bridge between the CITADEL workers and Google Apps Script.6It provides utilities for automating Google Sheets updates with inventory data7from all connected systems (S10, Oppo, Laptop, GDrive).8 9Usage:10 python apps_script_toolbox.py --identity-strike # Generate Identity Strike report11 python apps_script_toolbox.py --full-audit # Full archive audit to Sheets12 python apps_script_toolbox.py --worker-status # Update worker status dashboard13"""14 15import os16import sys17import json18import argparse19from pathlib import Path20from datetime import datetime21 22# Add parent directory to path for imports23REPO_ROOT = Path(__file__).parent.parent24sys.path.insert(0, str(REPO_ROOT))25 26try:27 from services.worker_reporter import ReporterWorker28 from services.worker_archivist import ArchivistWorker29except ImportError:30 print("โ ๏ธ Worker modules not found. Ensure services/ directory exists.")31 ReporterWorker = None32 ArchivistWorker = None33 34 35class AppsScriptToolbox:36 """37 Bridge between CITADEL workers and Google Apps Script38 """39 40 def __init__(self):41 self.reporter = None42 self.archivist = None43 self.repo_root = REPO_ROOT44 45 def initialize_workers(self):46 """Initialize the Reporter and Archivist workers"""47 print("๐ง Initializing CITADEL Workers...")48 49 if ReporterWorker is not None:50 try:51 self.reporter = ReporterWorker()52 print("โ
Reporter Worker initialized")53 except Exception as e:54 print(f"โ ๏ธ Reporter Worker failed: {e}")55 56 if ArchivistWorker is not None:57 try:58 self.archivist = ArchivistWorker()59 print("โ
Archivist Worker initialized")60 except Exception as e:61 print(f"โ ๏ธ Archivist Worker failed: {e}")62 63 def run_identity_strike(self):64 """65 Generate Identity Strike Report (Section 44 Audit)66 This report shows all files from connected systems67 """68 print("\n๐ฏ IDENTITY STRIKE REPORT - Section 44 Audit")69 print("=" * 60)70 71 if not self.reporter:72 print("โ Reporter Worker not available")73 return False74 75 try:76 result = self.reporter.create_identity_strike_report()77 print(f"โ
Identity Strike Report generated: {result}")78 return True79 except Exception as e:80 print(f"โ Identity Strike failed: {e}")81 return False82 83 def run_full_audit(self):84 """85 Run full archive audit and push to Google Sheets86 This processes all cargo bays and creates comprehensive inventory87 """88 print("\n๐ FULL ARCHIVE AUDIT")89 print("=" * 60)90 91 if not self.archivist:92 print("โ Archivist Worker not available")93 return False94 95 try:96 # Process all cargo bays97 cargo_bays = [98 self.repo_root / "Research" / "GDrive",99 self.repo_root / "Research" / "Oppo",100 self.repo_root / "Research" / "S10",101 self.repo_root / "Research" / "Laptop",102 self.repo_root / "S10_CITADEL_OMEGA_INTEL"103 ]104 105 for bay in cargo_bays:106 if bay.exists():107 print(f"๐ฆ Processing: {bay.name}")108 self.archivist.process_cargo_bay(str(bay))109 else:110 print(f"โญ๏ธ Skipping (not found): {bay.name}")111 112 # Save archive index113 self.archivist._save_archive_index()114 print(f"โ
Archive index saved: {self.archivist.files_processed} files processed")115 116 # Push to Google Sheets via Reporter117 if self.reporter:118 print("๐ค Pushing to Google Sheets...")119 self.reporter.create_archive_audit_report()120 121 return True122 except Exception as e:123 print(f"โ Full audit failed: {e}")124 return False125 126 def update_worker_status_dashboard(self):127 """128 Update Google Sheets with current worker status129 Shows sync times, errors, and system health130 """131 print("\n๐ WORKER STATUS DASHBOARD UPDATE")132 print("=" * 60)133 134 status_file = self.repo_root / "worker_status.json"135 136 if not status_file.exists():137 print("โ worker_status.json not found")138 return False139 140 try:141 with open(status_file, 'r') as f:142 status = json.load(f)143 144 print("Current Worker Status:")145 print(f" Last Updated: {status.get('last_updated', 'Unknown')}")146 print(f" GDrive Last Sync: {status.get('sync_status', {}).get('gdrive_last_sync', 'Never')}")147 148 if self.reporter:149 print("๐ค Pushing status to Google Sheets...")150 self.reporter.update_worker_status_sheet(status)151 print("โ
Worker status dashboard updated")152 153 return True154 except Exception as e:155 print(f"โ Status update failed: {e}")156 return False157 158 def verify_connections(self):159 """160 Verify all connections are working:161 - Google Sheets API162 - GDrive via rclone163 - S10_CITADEL_OMEGA_INTEL dataset link164 """165 print("\n๐ VERIFYING CONNECTIONS")166 print("=" * 60)167 168 checks_passed = 0169 checks_total = 0170 171 # Check 1: Google Sheets credentials172 checks_total += 1173 if os.environ.get("GOOGLE_SHEETS_CREDENTIALS"):174 print("โ
Google Sheets credentials found")175 checks_passed += 1176 else:177 print("โ Google Sheets credentials missing")178 179 # Check 2: Rclone config180 checks_total += 1181 if os.environ.get("RCLONE_CONFIG_DATA"):182 print("โ
Rclone configuration found")183 checks_passed += 1184 else:185 print("โ Rclone configuration missing")186 187 # Check 3: HuggingFace token188 checks_total += 1189 if os.environ.get("HF_TOKEN"):190 print("โ
HuggingFace token found")191 checks_passed += 1192 else:193 print("โ HuggingFace token missing")194 195 # Check 4: Worker files196 checks_total += 1197 worker_files = [198 self.repo_root / "services" / "worker_reporter.py",199 self.repo_root / "services" / "worker_archivist.py",200 ]201 202 all_workers_present = all(f.exists() for f in worker_files)203 if all_workers_present:204 print("โ
All worker files present")205 checks_passed += 1206 else:207 print("โ Some worker files missing")208 209 print(f"\n๐ Connection Check: {checks_passed}/{checks_total} passed")210 return checks_passed == checks_total211 212 213def main():214 parser = argparse.ArgumentParser(description="CITADEL Apps Script Toolbox")215 parser.add_argument("--identity-strike", action="store_true",216 help="Generate Identity Strike Report (Section 44 Audit)")217 parser.add_argument("--full-audit", action="store_true",218 help="Run full archive audit and push to Google Sheets")219 parser.add_argument("--worker-status", action="store_true",220 help="Update worker status dashboard in Google Sheets")221 parser.add_argument("--verify", action="store_true",222 help="Verify all connections are working")223 224 args = parser.parse_args()225 226 # Print banner227 print("\n" + "=" * 60)228 print("๐ ๏ธ APPS SCRIPT TOOLBOX - CITADEL MASTER BRIDGE")229 print("=" * 60)230 231 toolbox = AppsScriptToolbox()232 233 if args.verify:234 success = toolbox.verify_connections()235 sys.exit(0 if success else 1)236 237 # Initialize workers for other commands238 toolbox.initialize_workers()239 240 if args.identity_strike:241 success = toolbox.run_identity_strike()242 sys.exit(0 if success else 1)243 244 if args.full_audit:245 success = toolbox.run_full_audit()246 sys.exit(0 if success else 1)247 248 if args.worker_status:249 success = toolbox.update_worker_status_dashboard()250 sys.exit(0 if success else 1)251 252 # If no arguments, show help253 parser.print_help()254 255 256if __name__ == "__main__":257 main()258 