|
| 1 | +import requests |
| 2 | +import time |
| 3 | +import os |
| 4 | +import ctypes |
| 5 | +import json |
| 6 | +import hashlib |
| 7 | +from selenium import webdriver |
| 8 | +from selenium.webdriver.chrome.service import Service |
| 9 | +from selenium.webdriver.chrome.options import Options |
| 10 | +from selenium.webdriver.common.by import By |
| 11 | +from webdriver_manager.chrome import ChromeDriverManager |
| 12 | + |
| 13 | +# --- CONFIGURATION --- |
| 14 | +DRIVE_PATH = "A:\\Pi.txt" |
| 15 | +META_PATH = "A:\\Pi_Metadata.json" |
| 16 | +COMET_PATH = r"C:\Program Files\Comet\Browser\Comet.exe" # Path to Comet browser |
| 17 | +API_URL = "https://api.pi.delivery/v1/pi" |
| 18 | +CHUNK_SIZE = 100000 # 1 Lakh digits per API call |
| 19 | +LAKH = 100000 # Validation Milestone |
| 20 | +TRILLION = 10**12 # 1,000,000,000,000 |
| 21 | + |
| 22 | +class PiTitan: |
| 23 | + def __init__(self): |
| 24 | + self.session = requests.Session() |
| 25 | + self.current_pos = self.load_state() |
| 26 | + self.desmos_seed = "" |
| 27 | + |
| 28 | + def get_seed_silently(self): |
| 29 | + """Launches Comet in the background to get Desmos 15-digit Pi.""" |
| 30 | + options = Options() |
| 31 | + options.binary_location = COMET_PATH |
| 32 | + options.add_argument("--headless=new") |
| 33 | + options.add_argument("--disable-gpu") |
| 34 | + |
| 35 | + try: |
| 36 | + driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) |
| 37 | + driver.get("https://www.desmos.com/calculator") |
| 38 | + time.sleep(4) |
| 39 | + expr = driver.find_element(By.CLASS_NAME, "dcg-mq-editable-field") |
| 40 | + expr.send_keys("4*arctan(1)") |
| 41 | + time.sleep(2) |
| 42 | + res = driver.find_element(By.CLASS_NAME, "dcg-evaluation").text |
| 43 | + driver.quit() |
| 44 | + return res.replace("= ", "").strip() |
| 45 | + except: |
| 46 | + return "3.14159265358979" |
| 47 | + |
| 48 | + def load_state(self): |
| 49 | + if os.path.exists(META_PATH): |
| 50 | + with open(META_PATH, "r") as f: |
| 51 | + return json.load(f).get("last_digit", 0) |
| 52 | + return max(0, os.path.getsize(DRIVE_PATH) - 2) if os.path.exists(DRIVE_PATH) else 0 |
| 53 | + |
| 54 | + def save_state(self): |
| 55 | + with open(META_PATH, "w") as f: |
| 56 | + json.dump({"last_digit": self.current_pos, "time": time.time()}, f) |
| 57 | + |
| 58 | + def fetch_block(self, start, count): |
| 59 | + for _ in range(3): # Retry logic |
| 60 | + try: |
| 61 | + r = self.session.get(API_URL, params={'start': start, 'numberOfDigits': count}, timeout=25) |
| 62 | + if r.status_code == 200: return r.json().get("content", "") |
| 63 | + except: time.sleep(5) |
| 64 | + return None |
| 65 | + |
| 66 | + def validate(self): |
| 67 | + """Cross-checks the last 1 Lakh digits for any corruption.""" |
| 68 | + if self.current_pos < LAKH: return True |
| 69 | + start = self.current_pos - LAKH |
| 70 | + truth = self.fetch_block(start, LAKH) |
| 71 | + with open(DRIVE_PATH, "r") as f: |
| 72 | + f.seek(start + 2) |
| 73 | + local = f.read(LAKH) |
| 74 | + return hashlib.md5(local.encode()).hexdigest() == hashlib.md5(truth.encode()).hexdigest() |
| 75 | + |
| 76 | + def run(self): |
| 77 | + print(f"[SYSTEM] Performing silent Comet/Desmos handshake...") |
| 78 | + self.desmos_seed = self.get_seed_silently() |
| 79 | + |
| 80 | + if not os.path.exists(DRIVE_PATH): |
| 81 | + with open(DRIVE_PATH, "w") as f: f.write("3.") |
| 82 | + |
| 83 | + print(f"Resuming at {self.current_pos:,} digits. Target: 1 Trillion.") |
| 84 | + |
| 85 | + while self.current_pos < TRILLION: |
| 86 | + data = self.fetch_block(self.current_pos, CHUNK_SIZE) |
| 87 | + if data: |
| 88 | + with open(DRIVE_PATH, "a") as f: |
| 89 | + f.write(data) |
| 90 | + f.flush() |
| 91 | + |
| 92 | + self.current_pos += len(data) |
| 93 | + |
| 94 | + # Check accuracy against Comet for the very first block |
| 95 | + if self.current_pos == CHUNK_SIZE and data[:10] != self.desmos_seed[2:12]: |
| 96 | + print("\n[!] WARNING: Seed mismatch between Desmos and API.") |
| 97 | + |
| 98 | + # Every 1 Lakh: Validate & Save |
| 99 | + if self.current_pos % LAKH == 0: |
| 100 | + if not self.validate(): |
| 101 | + print(f"\n[!] Error at {self.current_pos}. Repairing...") |
| 102 | + self.current_pos -= LAKH |
| 103 | + with open(DRIVE_PATH, "rb+") as f: f.truncate(self.current_pos + 2) |
| 104 | + self.save_state() |
| 105 | + |
| 106 | + print(f"\rStreaming: {self.current_pos:,} / {TRILLION:,}", end="") |
| 107 | + else: |
| 108 | + print("\n[!] Network lag. Retrying...") |
| 109 | + |
| 110 | + ctypes.windll.user32.MessageBoxW(0, "Task Complete: Pi reached 1 Trillion.", "Success", 0x40) |
| 111 | + |
| 112 | +if __name__ == "__main__": |
| 113 | + PiTitan().run() |
0 commit comments