Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/store/tests/radcrawl.py # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / store / tests / radcrawl.py` 106 lines ยท 5807 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # ORACLE: host test driver, not product code. 3 # store/tests/radcrawl.py BASE LIMIT OUT.json: crawl a running forge from BASE (seeds below, then the 4 # links it finds on the same host, up to LIMIT addresses) and count the Radicle patterns of 5 # RadFreeForgeAndSI's crawl (~/work/hive/rad-free-si/crawl.py, the same regular expression) in what the 6 # forge itself writes. Repository content is left out of the count: every page of a repository below 7 # its home (blob, raw, blame, tree, commit, commits, compare, releases, archive, search), the result 8 # lines of the forge-wide code search (/search?q=: lines of repository files), and, on a 9 # project home, the README, the description and the last commit subject (HTML: the readme box, the 10 # desc paragraph and the Last commit line; JSON: the readme, description and last_commit values; 11 # text form: from the README.md heading on, and the description and last commit lines). 12 # Prints one FORGE line per address with forge-written hits, then 13 # RADCRAWL urls=N forge_hits=H content_hits=C codes={...} 14 # and exits 1 when H > 0, 0 otherwise. OUT.json gets every row. 15 import json, re, sys, urllib.error, urllib.parse, urllib.request 16 from collections import deque 17 18 P = re.compile(r'radicle|\brad:z[1-9A-HJ-NP-Za-km-z]{10,}|\brad (clone|init|sync|id|patch|auth)|/rad/|heartwood|radicle\.(xyz|network|garden|dev)', re.I) 19 BASE, LIMIT, OUT = sys.argv[1], int(sys.argv[2]), sys.argv[3] 20 SEEDS = ['/', '/explore', '/explore.json', '/explore?format=text', '/agents.json', '/agents.json?format=text', 21 '/events.json', '/events.json?limit=200', '/feed', '/feed?format=text', '/drakestapleton', 22 '/drakestapleton?format=text', '/drakestapleton.json', '/login', '/stars', '/search?q=forge', 23 '/drakestapleton/hop', '/drakestapleton/hop.json', '/drakestapleton/hop?format=text', 24 '/drakestapleton/omega-mv', '/drakestapleton/omega-mv.json', '/drakestapleton/omega-mv?format=text', 25 '/drakestapleton/cuda-crack', '/drakestapleton/cuda-crack.json', '/drakestapleton/interplane.io', 26 '/status', '/status.json', '/open/', '/drakestapleton/hop/patches', '/no-such-page-x'] 27 CONTENT = re.compile(r'^(/[^/?]+/[^/?]+/(blob|raw|blame|tree|commit|commits|compare|releases|archive|search)(/|\?|$)|/search\?)') 28 HOME = re.compile(r'^/[^/?]+/([^/?]+?)(\.json)?(\?format=text)?$') 29 host = urllib.parse.urlparse(BASE).netloc 30 31 def fetch(u): 32 class NR(urllib.request.HTTPRedirectHandler): 33 def redirect_request(self, *a, **k): return None 34 try: 35 r = urllib.request.build_opener(NR).open(urllib.request.Request(BASE + u, headers={'User-Agent': 'radcrawl'}), timeout=60) 36 return r.status, r.headers.get('Content-Type', ''), r.read() 37 except urllib.error.HTTPError as e: 38 return e.code, e.headers.get('Content-Type', ''), e.read() 39 40 def forge_part(u, ct, t): 41 """the text the forge itself wrote on page u (repository content cut out)""" 42 if CONTENT.match(u.split('#')[0]): 43 return '' 44 m = HOME.match(u) 45 if not m or u.startswith(('/drakestapleton?', '/drakestapleton.json')) or m.group(1) in ('followers', 'following'): 46 return t 47 if 'json' in ct: 48 try: 49 d = json.loads(t) 50 except ValueError: 51 return t 52 if isinstance(d, dict) and d.get('schema') == 'forge/repo/1': 53 for k in ('readme', 'description', 'last_commit', 'files'): 54 d.pop(k, None) 55 return json.dumps(d) 56 return t 57 if 'text/plain' in ct: 58 t = t.split('\nREADME.md', 1)[0] 59 return '\n'.join(l for l in t.split('\n') if not l.startswith(('Last commit', 'Description'))) 60 # HTML: the readme box up to the developer section, the description, the last commit line 61 t = re.sub(r'