TITAN REMOTE TELEMETRY // PACKET: 2026-01-18_Day-01 PACKET_REGEX = re.compile( r"TITAN REMOTE TELEMETRY // PACKET:\s*([\w\-\.]+)", re.IGNORECASE ) ## ## # Reserved for future automated body modifications. ## # ============================================================================= # --- RECEIVER LOGIC --- # ============================================================================= ## class TitanReceiver: """ Parses bulk telemetry and files it into the Mission Logs. """ def __init__(self): self.ingest_buffer = "" if not os.path.exists(LOGS_DIR): try: os.makedirs(LOGS_DIR) except OSError: print(f"[FAIL] Could not create logs dir: {LOGS_DIR}") def capture_input(self): """Captures bulk text from Clipboard or Stdin.""" if HAS_CLIPBOARD: print("\n>> Checking Clipboard for Telemetry...") content = pyperclip.paste() if "TITAN REMOTE TELEMETRY" in content: print(f"[SUCCESS] Telemetry detected ({len(content)} chars).") self.ingest_buffer = content return True else: print("[INFO] Clipboard does not contain valid Telemetry.") print(f"\n[MANUAL] Paste Telemetry Packets below. Type 'END' on a new line to finish:\n") lines = [] while True: try: line = input() if line.strip().upper() == 'END': break lines.append(line) except (EOFError, KeyboardInterrupt): break self.ingest_buffer = "\n".join(lines) return len(self.ingest_buffer) > 0 def process_packets(self): """Slices buffer into files.""" if not self.ingest_buffer: print("[WARN] Buffer empty.") return # Split by header # We look for the start index of each match matches = list(PACKET_REGEX.finditer(self.ingest_buffer)) if not matches: print("[FAIL] No valid Packet Headers found.") print("Expected: TITAN REMOTE TELEMETRY // PACKET: [ID]") return print(f"\n[ANALYSIS] Found {len(matches)} Packets.") for i, match in enumerate(matches): packet_id = match.group(1).strip() start_idx = match.start() # Determine end index (start of next match or end of string) end_idx = matches[i+1].start() if i + 1 < len(matches) else len(self.ingest_buffer) content = self.ingest_buffer[start_idx:end_idx].strip() # Format filename filename = f"Log_{packet_id}.txt" filepath = os.path.join(LOGS_DIR, filename) try: with open(filepath, 'w', encoding='utf-8') as f: f.write(content) print(f" -> Filed: {filename}") except OSError as e: print(f" -> [ERR] Failed to write {filename}: {e}") def trigger_historian(self): """Calls Deep Field to update the website.""" print(f"\n[LINK] Triggering The Historian...") if os.path.exists(DEEP_FIELD_PATH): try: subprocess.run([sys.executable, DEEP_FIELD_PATH], check=False) except Exception as e: # pylint: disable=broad-exception-caught print(f"[FAIL] Could not run Deep Field: {e}") else: print(f"[FAIL] Deep Field not found at: {DEEP_FIELD_PATH}") ## # ============================================================================= # --- IGNITION --- # ============================================================================= ## def main(): print(f"--- TITAN RECEIVER v{VERSION} ---") receiver = TitanReceiver() if receiver.capture_input(): receiver.process_packets() receiver.trigger_historian() else: print("[ABORT] No input provided.") ## ## # Reserved for future automated footer modifications. ## ## if __name__ == "__main__": main() ##