← back to Rentv Sheet Enrich Refine
apply_phones.py
24 lines
#!/usr/bin/env python3
"""
apply_phones.py — write scraped company phones into the master's "Company Phone (found)".
Matches each row's Website (domain) to data/phones.json; fills only empty cells, greened.
"""
import lib, json, os
GID = 3823360
tok = lib.access_token()
title = {s["properties"]["sheetId"]: s["properties"]["title"] for s in lib.get_meta(tok)["sheets"]}[GID]
rows = lib.read_tab(tok, title); hdr = rows[0]
def g(r,i): return (r[i] if i<len(r) else "").strip()
wi = hdr.index("Website")
pi = hdr.index("Company Phone (found)")
phones = json.load(open(os.path.join(os.path.dirname(__file__),"data","phones.json")))
cells = []
for r in range(1, len(rows)):
dom = g(rows[r], wi)
ph = phones.get(dom)
if dom and ph and not g(rows[r], pi):
cells.append({"row0": r, "col0": pi, "value": ph})
res = lib.batch_fill(tok, GID, cells)
found = sum(1 for v in phones.values() if v)
print(json.dumps({"domains": len(phones), "with_phone": found, "cells_written": res.get("totalUpdatedCells",0)}))