"""Clawmo Sweep — sweep one handle across hundreds of sites, streaming hits as they land.
Lite build of the Clawmo engine. Engine: sherlock-project (open source).
Full engine: https://clawmo.net
"""
import html
import os
import re
import threading
import time
import gradio as gr
import sherlock_project
from sherlock_project.notify import QueryNotify
from sherlock_project.result import QueryStatus
from sherlock_project.sherlock import sherlock
from sherlock_project.sites import SitesInformation
# --------------------------------------------------------------------------
# Site manifest (bundled with the package — no network needed at boot)
# --------------------------------------------------------------------------
SHERLOCK_VERSION = sherlock_project.__version__
_DATA_PATH = os.path.join(
os.path.dirname(os.path.abspath(sherlock_project.__file__)), "resources", "data.json"
)
_sites = SitesInformation(_DATA_PATH, honor_exclusions=True)
_sites.remove_nsfw_sites()
SITE_DATA = {s.name: s.information for s in _sites}
TOTAL_SITES = len(SITE_DATA)
REQUEST_TIMEOUT = 8.0 # per-site HTTP timeout
HARD_TIMEOUT = 75.0 # overall wall clock cap for one sweep
POLL = 0.35 # stream tick
MAX_WORKERS = 20 # sherlock's own bounded worker pool
MAX_ROWS = 400 # rendered rows cap (never silently drops the count)
HANDLE_RE = re.compile(r"^[A-Za-z0-9._-]{1,64}$")
CSS = """
:root {
--forge-black:#0A0908; --black-2:#12100D; --gold:#D4A843; --gold-light:#E8C56D;
--gold-muted:#8A7440; --stone:#6B6560; --bone:#F0EDE8; --hairline:#2A2418;
}
body, gradio-app, .gradio-container, .dark, .gradio-container .prose {
background: var(--forge-black) !important;
color: var(--bone) !important;
}
.gradio-container { max-width: 1040px !important; margin: 0 auto !important; }
.gradio-container .prose :is(h1,h2,h3,p,li,span) { color: var(--bone) !important; }
#hdr { border:1px solid var(--hairline); background:var(--black-2); border-radius:10px;
padding:16px 20px; margin-bottom:14px; }
#hdr .mark { font-size:26px; }
#hdr h1 { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size:22px;
letter-spacing:.04em; margin:6px 0 4px 0; color:var(--gold-light) !important; }
#hdr p { margin:2px 0; color:var(--stone) !important; font-size:13px; }
#hdr .stat { color:var(--gold) !important; font-family: ui-monospace, Menlo, monospace; }
#panel { border:1px solid var(--hairline); background:var(--black-2); border-radius:10px;
padding:14px 16px; min-height:120px; }
#panel .bar { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size:13px;
color:var(--gold); border-bottom:1px solid var(--hairline);
padding-bottom:10px; margin-bottom:10px; }
#panel .bar .n { color:var(--gold-light); font-weight:700; }
#panel .bar .mut { color:var(--stone); }
#panel ol { list-style:none; margin:0; padding:0; }
#panel li.hit { display:flex; gap:12px; align-items:baseline; padding:7px 0;
border-bottom:1px solid var(--hairline); }
#panel li.hit .site { flex:0 0 210px; color:var(--bone); font-size:13px; }
#panel li.hit a { color:var(--gold-light); text-decoration:none; font-size:12.5px;
font-family: ui-monospace, Menlo, monospace; word-break:break-all; }
#panel li.hit a:hover { color:var(--gold); text-decoration:underline; }
#panel .note { font-size:13px; padding:8px 0; }
#panel .note.warn { color:#E8C56D; }
#panel .note.bad { color:#C96A4E; }
#panel .note.mut { color:var(--stone); }
#panel .empty { color:var(--stone); font-size:13px; padding:10px 0; }
#foot { margin-top:16px; padding-top:12px; border-top:1px solid var(--hairline);
color:var(--stone); font-size:12px; }
#foot a { color:var(--gold-muted); text-decoration:none; }
#foot a:hover { color:var(--gold); }
"""
HEADER = f"""
🦀
CLAWMO SWEEP
One handle. {TOTAL_SITES} sites.
{MAX_WORKERS} concurrent workers.
Hits stream in as they land.
Lite version of the full Clawmo engine. Results, not adjectives.
"""
FOOTER = f"""
"""
# --------------------------------------------------------------------------
# Validation
# --------------------------------------------------------------------------
def validate(raw):
"""Return (handle, error_message)."""
handle = (raw or "").strip()
if not handle:
return None, "Enter a handle to sweep."
if " " in handle:
return None, "No spaces in a handle. Try something like jane_doe."
if len(handle) > 64:
return None, "Handle too long — 64 characters max."
if not HANDLE_RE.match(handle):
return None, "Letters, numbers, dot, dash and underscore only."
return handle, None
# --------------------------------------------------------------------------
# Engine bridge
# --------------------------------------------------------------------------
class StreamNotify(QueryNotify):
"""Collects sherlock's per-site verdicts as the sweep resolves them."""
def __init__(self):
super().__init__(None)
self.lock = threading.Lock()
self.hits = [] # (site_name, profile_url)
self.resolved = 0 # sites the engine has returned a verdict for
def start(self, message=None):
pass
def update(self, result):
with self.lock:
self.resolved += 1
if result.status == QueryStatus.CLAIMED and result.site_url_user:
self.hits.append((result.site_name, result.site_url_user))
def finish(self, message=None):
pass
def snapshot(self):
with self.lock:
return list(self.hits), self.resolved
def _run_engine(handle, notify, state):
try:
# sherlock stores request futures on the per-site dicts, so hand it a copy.
site_data = {k: dict(v) for k, v in SITE_DATA.items()}
sherlock(handle, site_data, notify, timeout=REQUEST_TIMEOUT)
except Exception as exc: # noqa: BLE001
state["error"] = f"{type(exc).__name__}: {exc}"
finally:
state["done"] = True
# --------------------------------------------------------------------------
# Rendering
# --------------------------------------------------------------------------
def _esc(value):
return html.escape(str(value), quote=True)
def _panel(counter_html, body_html):
return f'{counter_html}
{body_html}
'
def _hits_body(hits, truncated):
if not hits:
return 'No hits yet.
'
rows = []
# newest first — arrivals land at the top as they stream in
for name, url in reversed(hits[:MAX_ROWS]):
rows.append(
''
f'{_esc(name)}'
f'{_esc(url)}'
""
)
body = "" + "".join(rows) + "
"
if truncated:
body += (
f'Showing first {MAX_ROWS} of {len(hits)} hits — '
"count above is complete.
"
)
return body
def _counter(handle, n_hits, resolved, elapsed, done, timed_out):
if done:
state = 'complete'
elif timed_out:
state = 'partial'
else:
state = 'sweeping…'
return (
f'{_esc(handle)} · {n_hits} hits'
f' · {resolved}/{TOTAL_SITES} sites resolved'
f' · {elapsed:.0f}s · {state}'
)
def _error_panel(message):
return _panel(
'input rejected',
f'{_esc(message)}
',
)
# --------------------------------------------------------------------------
# The sweep (generator — yields progressively)
# --------------------------------------------------------------------------
def sweep(handle: str):
"""Sweep a username across all sites and stream the hits that exist.
Args:
handle: the username to look up (no spaces).
"""
cleaned, error = validate(handle)
if error:
yield _error_panel(error)
return
notify = StreamNotify()
state = {"done": False, "error": None}
worker = threading.Thread(
target=_run_engine, args=(cleaned, notify, state), daemon=True
)
started = time.time()
worker.start()
deadline = started + HARD_TIMEOUT
while True:
hits, resolved = notify.snapshot()
done = bool(state["done"])
timed_out = (not done) and time.time() >= deadline
elapsed = time.time() - started
body = _hits_body(hits, len(hits) > MAX_ROWS)
if not done and not timed_out:
body += 'Scanning… hits appear here as they land.
'
if timed_out:
body += (
'PARTIAL — TIMED OUT after '
f'{int(HARD_TIMEOUT)}s. {resolved} of {TOTAL_SITES} sites resolved. '
"Hits above are real; the rest were never checked. "
"Run again for the remainder.
"
)
if done and state["error"]:
body += f'Engine error: {_esc(state["error"])}
'
if done and not state["error"] and not hits:
body += 'Engine finished clean. Zero hits on this handle.
'
yield _panel(_counter(cleaned, len(hits), resolved, elapsed, done, timed_out), body)
if done or timed_out:
break
time.sleep(POLL)
# --------------------------------------------------------------------------
# UI
# --------------------------------------------------------------------------
with gr.Blocks(title="Clawmo Sweep") as demo:
gr.HTML(HEADER)
with gr.Row():
handle = gr.Textbox(
show_label=False,
placeholder="handle — e.g. jane_doe",
container=False,
scale=5,
)
run_btn = gr.Button("Sweep", variant="primary", scale=1)
demo_btn = gr.Button("Demo: torvalds", scale=1)
out = gr.HTML(_panel('idle', 'No hits yet.
'))
run_btn.click(sweep, inputs=handle, outputs=out, api_name="sweep")
handle.submit(sweep, inputs=handle, outputs=out, api_name="sweep_enter")
demo_btn.click(lambda: "torvalds", inputs=None, outputs=handle).then(
sweep, inputs=handle, outputs=out, api_name="sweep_demo"
)
gr.Examples(
examples=[["torvalds"], ["naval"], ["jack"], ["pmarca"]],
inputs=handle,
outputs=out,
fn=sweep,
cache_examples=False,
label="Well-known handles",
)
gr.HTML(FOOTER)
if __name__ == "__main__":
demo.queue(default_concurrency_limit=2).launch(
css=CSS, theme=gr.themes.Base(), mcp_server=True
)