Snippet content copied to clipboard.
Are you sure to delete this snippet? No, don't delete
  1. import os
  2. os.makedirs('sovereign_grid',exist_ok=True)
  3. os.chdir('sovereign_grid')
  4. open('README_V16.txt','w').write('SOVEREIGN GRID V16.0 - LOCAL-FIRST PERSONAL MESH\n\nWHY I BUILT THIS:\nBuilt as a passion project for anyone who wants their iPad, iPhone, and Apple Watch to talk directly over home Wi-Fi with zero cloud accounts, subscriptions, or tracking.\n\nWHAT IS NEW IN V16.0:\n- In-browser +Ticker, +Card, Find search, and Spaced-Repetition Quiz.\n- 3-second cellular timeout with cached stock fallback.\n- Live Audit activity log and one-tap local Backup.\n\nHONEST CAVEAT:\n- Keep a-Shell open in the foreground or Split View on your host iPad so iPadOS keeps Port 5002 awake.\n\n3-MINUTE SETUP:\n1. Run this installer in a-Shell on your iPad (your Master Hub).\n2. Open http://127.0.0.1:5002 in Safari to use your dashboard.\n3. Point an Apple Shortcut (Get Contents of URL -> Show Content) at http://<YOUR-IPAD-IP>:5002/watch for one-tap wrist briefings.\n')
  5. open('master_mesh.py','w').write('import os,urllib.parse,recv,watch\nnl=chr(10)\nfrom http.server import *\nclass H(BaseHTTPRequestHandler):\n def do_GET(self):\n u=urllib.parse.urlparse(self.path)\n c=u.path.strip(\'/\'); qs=u.query\n import time; L=open(\'audit_log.txt\').read().splitlines() if os.path.exists(\'audit_log.txt\') else []; L.insert(0,time.strftime(\'%H:%M:%S\')+" | "+self.client_address[0]+" | "+self.path); open(\'audit_log.txt\',\'w\').write(nl.join(L[:30])+nl); self.send_response(200); self.end_headers()\n if not c: self.wfile.write(open(\'dash.html\',\'rb\').read())\n elif c==\'receive\': recv.save(qs); self.wfile.write(b\'OK\')\n elif c==\'stocks\': self.wfile.write(watch.stocks.live().encode())\n elif c==\'watch\': self.wfile.write(watch.brief().encode())\n elif c==\'cards\': self.wfile.write(open(\'study_cards.txt\',\'rb\').read())\n elif c==\'todos\': self.wfile.write(open(\'todos.txt\',\'rb\').read())\n elif c==\'read\': self.wfile.write(open(\'clipboard_notes.txt\',\'rb\').read())\n elif c==\'add\': open(\'todos.txt\',\'a\').write(urllib.parse.unquote(qs).strip()+nl)\n elif c==\'note\': open(\'clipboard_notes.txt\',\'a\').write(urllib.parse.unquote(qs).strip()+nl)\n elif c==\'ticker\': open(\'tickers.txt\',\'a\').write(urllib.parse.unquote(qs).strip().upper()+nl); self.wfile.write(watch.stocks.live().encode())\n elif c==\'card\': open(\'study_cards.txt\',\'a\').write(urllib.parse.unquote(qs).strip()+nl); self.wfile.write(open(\'study_cards.txt\',\'rb\').read())\n elif c==\'del\': m=dict(urllib.parse.parse_qsl(qs)); fn=m[\'f\']; L=open(fn).read().splitlines(); L.pop(int(m[\'i\'])); open(fn,\'w\').write(nl.join(L)+(nl if L else \'\')); self.wfile.write(open(fn,\'rb\').read())\n elif c==\'find\': k=urllib.parse.unquote(qs).lower(); res=[f+" -> "+l for f in (\'todos.txt\',\'clipboard_notes.txt\',\'study_cards.txt\') for l in open(f).read().splitlines() if k in l.lower()]; self.wfile.write((nl.join(res) or \'NO MATCHES\').encode())\n elif c==\'backup\': import shutil,time; d=\'backups/snap_\'+time.strftime(\'%Y%m%d_%H%M%S\'); os.makedirs(d,exist_ok=True); [shutil.copy(f,d) for f in os.listdir(\'.\') if os.path.isfile(f)]; self.wfile.write(b\'BACKUP SAVED: \'+d.encode())\n elif c==\'audit\': self.wfile.write((open(\'audit_log.txt\',\'rb\').read() if os.path.exists(\'audit_log.txt\') else b\'NO LOGS YET\'))\nHTTPServer.allow_reuse_address=True\nprint(\'πŸš€ [MASTER MESH V16.0]: Online on Port 5002. [A_STABLE]\')\nHTTPServer((\'0.0.0.0\',5002),H).serve_forever()\n')
  6. open('dash.html','w').write('<html><meta name="viewport" content="width=device-width,initial-scale=1"><style>button{padding:10px 12px;font-size:15px;border-radius:8px;border:none;color:#fff;background:#21262d;font-weight:600}</style><body style="background:#0d1117;color:#c9d1d9;font-family:sans-serif;padding:16px"><h2>Sovereign Grid V16.0</h2><div id=stat style="margin-bottom:8px;color:#58a6ff;font-size:14px"></div><input id=msg style="width:100%;padding:10px;margin-bottom:10px"><div style="display:flex;flex-wrap:wrap;gap:6px"><button onclick=send(\'/note?\')>Note</button><button onclick=send(\'/add?\')>Task</button><button onclick=hit(\'/todos\')>Tasks</button><button onclick=hit(\'/read\')>Notes</button><button onclick=hit(\'/stocks\')>Stocks</button><button onclick=hit(\'/watch\')>Watch</button><button onclick=hit(\'/cards\')>Cards</button><button onclick=send(\'/ticker?\')>+ Ticker</button><button onclick=send(\'/card?\')>+ Card</button><button onclick=quiz()>Quiz</button><button onclick=send(\'/find?\')>Find</button><button onclick=quiz(1)>Review Missed</button><button onclick=resetQ()>Reset</button><button onclick=hit(\'/backup\')>Backup</button><button onclick=hit(\'/audit\')>Audit</button></div><pre id=out></pre><script>async function hit(u){r=await fetch(u);t=await r.text();o=document.getElementById(\'out\');render(u,t)}function send(p){v=document.getElementById(\'msg\').value;if(v)hit(p+encodeURIComponent(v));document.getElementById(\'msg\').value=\'\'}function upd(){m=JSON.parse(localStorage.getItem(\'miss\')||\'[]\');document.getElementById(\'stat\').innerText=\'Review Queue: \'+m.length+\' card(s) flagged\'}upd();function quiz(only){fetch(\'/cards\').then(r=>r.text()).then(t=>{L=t.trim().split(String.fromCharCode(10));m=JSON.parse(localStorage.getItem(\'miss\')||\'[]\');P=only&&m.length?m:L.concat(m,m);raw=P[Math.floor(Math.random()*P.length)];c=raw.split(\'|\');o=document.getElementById(\'out\');o.innerHTML=\'<b>Q: </b>\'+c[0]+\'<br><br><button onclick=this.nextSibling.style.display="block">Reveal Answer</button><div style="display:none;margin-top:10px;color:#58a6ff"><b>A: </b>\'+(c[1]||\'\')+\'<br><br><button onclick=mark(1)>Got It βœ…</button> <button onclick=mark(0)>Missed ❌</button></div>\'})}function mark(ok){m=JSON.parse(localStorage.getItem(\'miss\')||\'[]\');m=ok?m.filter(x=>x!==raw):[...new Set([...m,raw])];localStorage.setItem(\'miss\',JSON.stringify(m));upd();quiz(0)}function resetQ(){localStorage.removeItem(\'miss\');upd();document.getElementById(\'out\').innerText=\'MASTERY RESET\'}function render(u,t){o=document.getElementById(\'out\');fm={\'/todos\':\'todos.txt\',\'/read\':\'clipboard_notes.txt\',\'/tickers\':\'tickers.txt\'};if(fm[u]){L=t.trim()?t.trim().split(String.fromCharCode(10)):[];o.innerHTML=L.map((x,i)=>x+\' <button onclick=delItem("\'+fm[u]+\'",\'+i+\',"\'+u+\'")>βœ•</button>\').join(\'<br>\')||\'EMPTY\';return}o.innerText=t}function delItem(f,i,u){fetch(\'/del?f=\'+f+\'&i=\'+i).then(()=>hit(u))}</script></body></html>')
  7. open('recv.py','w').write("import urllib.parse as p\ndef save(qs):\n d=dict(p.parse_qsl(qs))\n open('todos.txt','w').write(d.get('t',''))\n open('clipboard_notes.txt','w').write(d.get('n',''))\n open('tickers.txt','w').write(d.get('k',''))\n open('study_cards.txt','w').write(d.get('c',''))\n")
  8. open('stocks.py','w').write('import urllib.request as u,json,os\ncf=\'stock_cache.json\'\nc=json.loads(open(cf).read()) if os.path.exists(cf) else {}\ns=chr(47)\nh=\'https:\'+s+s+\'query1.finance.yahoo.com\'+s+\'v8\'+s+\'finance\'+s+\'chart\'+s\ndef quote(t):\n try:\n r=u.Request(h+t+\'?interval=1d\',headers={\'User-Agent\':\'Mozilla/5.0\'})\n d=json.loads(u.urlopen(r,timeout=3).read()).get(\'chart\').get(\'result\').pop(0).get(\'meta\')\n p=str(d.get(\'regularMarketPrice\')); c[t]=p; open(cf,\'w\').write(json.dumps(c)); return t+": $"+p\n except Exception: return t+": $"+c.get(t,\'offline\')+" (cached)"\ndef live():\n ts=list(filter(None,(x.strip() for x in open(\'tickers.txt\').read().splitlines())))\n return chr(10).join(map(quote,ts))\n')
  9. open('watch.py','w').write("import stocks\ndef brief():\n t=open('todos.txt').read().strip() or 'ALL CLEAR'\n n=open('clipboard_notes.txt').read().strip() or 'NO NOTES'\n return 'TASKS:'+chr(10)+t+chr(10)+chr(10)+'NOTES:'+chr(10)+n+chr(10)+chr(10)+'STOCKS:'+chr(10)+stocks.live()\n")
  10. open('todos.txt','w').write('Explore Sovereign Grid V16.0'+chr(10))
  11. open('clipboard_notes.txt','w').write('Welcome to your local-first personal mesh!'+chr(10))
  12. open('tickers.txt','w').write('AAPL'+chr(10))
  13. open('study_cards.txt','w').write('What makes a mesh local-first?|Your devices talk directly over home Wi-Fi with zero cloud middleman.'+chr(10))
  14. exec(open('master_mesh.py').read())

Edit this Snippet