Skip to content

Free, open-source Google Maps scraper for lead generation (Python, no API key, no Docker). Exports name, phone, email, website, rating and Instagram/Facebook/LinkedIn/TikTok/YouTube/X links to CSV. 100 places with emails in 44 s; --grid beats Google's 120 cap. MX email check, ad-pixel detection. Skill for Claude Code, Codex and Cursor.

fix(ui): Enter picks nothing while a Where lookup is pending; a corrupt cities file leaves the engine up

Mahan Jafari16a2908950d2
diff --git a/CREDITS.md b/CREDITS.md
index 24e898b..af14e2c 100644
--- a/CREDITS.md
+++ b/CREDITS.md
@@ -38,7 +38,7 @@ The What box offers a hand-picked list of popular business types for this kit
from [lobstrio/google-business-categories](https://github.com/lobstrio/google-business-categories)
by lobstr.io. Your browser loads that list from GitHub at runtime, pinned to one commit in
`engine/serve.py`, and caches it for 30 days. This repository does not contain or redistribute it,
-because that repository has no license file. Offline, the box offers the kit's own list only.
+because that repository has no license file. Until the browser has fetched it once, the box offers the kit's own list only.
## Website signals adapted from OpenLeadFinder
diff --git a/SETUP.md b/SETUP.md
index 562b544..bcb35f9 100644
--- a/SETUP.md
+++ b/SETUP.md
@@ -124,8 +124,7 @@ profiles", under "Collect". Both read each business's homepage. Three collapsed
The job list shows each job's status with a progress bar, and CSV, JSON and Delete buttons. Job times
show in your local time, and a review stage reads "reading reviews 7 of 20". A job's error, if any,
-shows under its name. The business type box suggests Google's business category names (4,053, US
-English). Your browser loads that list from GitHub and keeps it for 30 days. The page downloads the
+shows under its name. The page downloads the
engine's raw rows, the rows so far while a job works, in a file named after the search (for example
`bakery-in-portland-or-c063a815.csv`). The scripts give you the cleaned 8 lead fields and find more
emails.
diff --git a/engine/serve.py b/engine/serve.py
index 24773fc..9b2d208 100644
--- a/engine/serve.py
+++ b/engine/serve.py
@@ -15,7 +15,7 @@ Google Maps, for email or socials jobs to the businesses' own websites, and for
to Google's public DNS (dns.google), nothing else.
Standard library only.
"""
-import argparse, csv, gzip, hmac, html, io, json, os, re, secrets, signal, socket, socketserver, sqlite3, sys, threading, unicodedata
+import argparse, csv, gzip, hmac, html, io, json, os, re, secrets, signal, socket, socketserver, sqlite3, sys, threading, unicodedata, zlib
import urllib.parse
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
@@ -51,8 +51,8 @@ def load_types(folder=None):
try:
with open(os.path.join(folder or PRESETS, "business-types.json"), encoding="utf-8") as f:
types = json.load(f)
- if not isinstance(types, list):
- raise ValueError("not a list")
+ if not isinstance(types, list) or not all(isinstance(t, str) for t in types):
+ raise ValueError("not a list of names")
return types
except (OSError, ValueError) as e:
print(f"presets/business-types.json unusable ({e.__class__.__name__}): the What box will be empty", file=sys.stderr)
@@ -104,7 +104,7 @@ def cities():
name, admin, cc, lat, lon = line.rstrip("\n").split("\t")
label = ", ".join([name] + ([admin] if admin and admin != name else []) + [cc])
rows.append("\t".join((fold(label), label, lat, lon, cc)))
- except (OSError, EOFError, ValueError) as e: # missing, truncated or odd file: what was read, once
+ except (OSError, EOFError, ValueError, zlib.error) as e: # missing, truncated, corrupt or odd file: what was read, once
log(f"presets/cities.tsv.gz unusable after {len(rows)} cities ({e.__class__.__name__})")
_cities = rows
return _cities
@@ -112,7 +112,9 @@ def cities():
def find_cities(q, limit=20):
"""The biggest cities whose "name, region, country" starts with q; with no q, the biggest in the US."""
- q, out = fold(q), []
+ raw, q, out = q.strip(), fold(q), []
+ if raw and not q: # punctuation only: nothing can start with it
+ return out
for row in cities(): # ponytail: a linear scan, about 30 ms; a prefix index if lookups ever lag
if row.startswith(q) if q else row.endswith("\tUS"):
_, label, lat, lon, cc = row.split("\t")
@@ -492,9 +494,9 @@ function tags(box, list) {{ // each pick is a button; pressing it removes the p
}});
}}
function combo(input, box, source, choose) {{ // a box that takes only picks from its own list: arrows move, Enter or a click picks
- let items = [], active = -1;
+ let items = [], active = -1, stale = false;
function show(list) {{
- items = list; active = list.length ? 0 : -1; box.replaceChildren();
+ items = list; active = list.length ? 0 : -1; stale = false; box.replaceChildren();
list.forEach((it, i) => {{
const li = document.createElement('li'); li.id = box.id + '-' + i; li.setAttribute('role', 'option'); li.textContent = it.label;
li.addEventListener('mousedown', ev => {{ ev.preventDefault(); pick(i); }}); box.appendChild(li);
@@ -507,7 +509,8 @@ function combo(input, box, source, choose) {{ // a box that takes only picks fr
input.setAttribute('aria-activedescendant', box.id + '-' + active); box.children[active].scrollIntoView({{block: 'nearest'}});
}}
function pick(i) {{ choose(items[i]); input.value = ''; say('', ''); source('', show); }}
- input.addEventListener('input', () => {{ if ($('msg').className === 'bad') say('', ''); source(input.value.trim(), show); }});
+ input.addEventListener('input', () => {{ // the list shown belongs to the old text until the source answers
+ items = []; active = -1; stale = true; mark(); if ($('msg').className === 'bad') say('', ''); source(input.value.trim(), show); }});
input.addEventListener('focus', () => source(input.value.trim(), show));
input.addEventListener('blur', () => show([]));
input.addEventListener('keydown', ev => {{
@@ -517,7 +520,7 @@ function combo(input, box, source, choose) {{ // a box that takes only picks fr
}} else if (ev.key === 'Enter') {{ // never submits the form
ev.preventDefault();
if (active >= 0) pick(active);
- else if (input.value.trim()) say('"' + input.value.trim() + '" is not in the list. Type a few letters, then pick from it.', 'bad');
+ else if (input.value.trim() && !stale) say('"' + input.value.trim() + '" is not in the list. Type a few letters, then pick from it.', 'bad');
}} else if (ev.key === 'Escape') show([]);
}});
}}
diff --git a/engine/test_engine.py b/engine/test_engine.py
index 7da41be..0066c21 100644
--- a/engine/test_engine.py
+++ b/engine/test_engine.py
@@ -1256,7 +1256,8 @@ class ApiP3(Server):
# each city, one job per city centred on it; downloads are named after the search; local times; a favicon
for rule in ("} else if (ev.key === 'Enter') { // never submits the form", "if (active >= 0) pick(active);",
"is not in the list", "is not picked yet", "whats.map(w => w + ' in ' + c.label)",
- "lat: c.lat, lon: c.lon", "for (const c of wheres)", "'/api/v1/cities?q=' + encodeURIComponent(q)"):
+ "lat: c.lat, lon: c.lon", "for (const c of wheres)", "'/api/v1/cities?q=' + encodeURIComponent(q)",
+ "stale = true", "!stale) say("): # Enter picks nothing while a lookup for newer text is pending
self.assertIn(rule, ui)
for gone in ('id="keywords"', 'id="coords"', 'id="kwpick"', "<datalist", "Start anyway"):
self.assertNotIn(gone, ui)
@@ -1296,17 +1297,23 @@ class Presets(Server):
tmp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmp, True)
self.assertEqual(serve.load_types(tmp), []) # no file
- with open(os.path.join(tmp, "business-types.json"), "w") as f:
- f.write("{not json")
- self.assertEqual(serve.load_types(tmp), [])
+ for bad in ("{not json", '["Dentists", 5]'):
+ with open(os.path.join(tmp, "business-types.json"), "w") as f:
+ f.write(bad)
+ self.assertEqual(serve.load_types(tmp), [])
with open(os.path.join(tmp, "cities.tsv.gz"), "wb") as f: # the real file cut short
with open(os.path.join(serve.PRESETS, "cities.tsv.gz"), "rb") as g:
f.write(g.read(5000))
- with unittest.mock.patch.object(serve, "PRESETS", tmp), unittest.mock.patch.object(serve, "_cities", None):
- code, body, _ = self.call("GET", "/api/v1/cities?q=aus")
- self.assertEqual(code, 200)
- self.assertIsInstance(json.loads(body), list)
- self.assertEqual(self.call("GET", "/api/v1/jobs")[0], 200)
+ for damage in ("cut", "flip"): # cut short (EOFError), one byte flipped inside a deflate block (zlib.error)
+ if damage == "flip":
+ with open(os.path.join(tmp, "cities.tsv.gz"), "r+b") as f:
+ f.seek(1124); b = f.read(1); f.seek(1124); f.write(bytes([b[0] ^ 0xFF]))
+ with unittest.mock.patch.object(serve, "PRESETS", tmp), unittest.mock.patch.object(serve, "_cities", None):
+ code, body, _ = self.call("GET", "/api/v1/cities?q=aus")
+ self.assertEqual(code, 200, damage)
+ self.assertIsInstance(json.loads(body), list)
+ self.assertEqual(self.call("GET", "/api/v1/jobs")[0], 200)
+ self.assertEqual(self.cities("!!!"), []) # punctuation only is not "nothing typed"
def test_where(self):
top = self.cities("") # nothing typed: the biggest US cities