← back to Dw Seo Report
send_report.py
52 lines
#!/usr/bin/env python3
"""Email the built report to steve@dw via George's local HTTP agent.
Reads George URL + basic-auth from ~/.claude.json at runtime (no secret in source)."""
import json, os, base64, urllib.request
HOME = os.path.expanduser("~")
REPORT = os.path.join(HOME, "Projects/dw-seo-report/index.html")
def find_george_env(o):
if isinstance(o, dict):
g = o.get("george")
if isinstance(g, dict) and isinstance(g.get("env"), dict) and g["env"].get("GEORGE_URL"):
return g["env"]
for v in o.values():
r = find_george_env(v)
if r: return r
elif isinstance(o, list):
for v in o:
r = find_george_env(v)
if r: return r
return None
cfg = json.load(open(os.path.join(HOME, ".claude.json")))
env = find_george_env(cfg)
assert env, "george MCP env not found in ~/.claude.json"
URL = env["GEORGE_URL"].rstrip("/")
AUTH = env["GEORGE_BASIC_AUTH"]
html = open(REPORT, encoding="utf-8").read()
b64 = base64.b64encode(html.encode("utf-8")).decode()
payload = {
"to": "steve@designerwallcoverings.com",
"account": "steve-office",
"subject": "DW Search Console Report — weekly SEO intelligence (designerwallcoverings.com)",
"body": ("<div style='font-family:-apple-system,Arial,sans-serif;max-width:640px;color:#1c1a17'>"
"<h2 style='font-family:Georgia,serif'>DW Search Console — weekly report</h2>"
"<p style='color:#6b6459'>Fresh Google Search Console pull for <b>designerwallcoverings.com</b>. "
"Full styled report attached — open <b>dw-seo-report.html</b> in a browser. "
"Covers the 6-month click trend, striking-distance keywords, cannibalization, top queries, "
"and drafted title/meta rewrites.</p>"
"<p style='color:#6b6459;font-size:13px'>Auto-generated from live GSC (free). "
"Local interactive viewer: http://127.0.0.1:50136 (admin / DW2024!).</p></div>"),
"attachments": [{"filename": "dw-seo-report.html", "content_base64": b64, "mime_type": "text/html"}],
}
req = urllib.request.Request(URL + "/api/send-with-attachment",
data=json.dumps(payload).encode(),
headers={"Authorization": "Basic " + AUTH, "Content-Type": "application/json"})
with urllib.request.urlopen(req, timeout=60) as r:
print("george:", r.read().decode()[:300])