From 3e41c60ccfbf732b58a81182356b6fe3112fe88e Mon Sep 17 00:00:00 2001 From: DariusDev16 Date: Mon, 9 Nov 2026 13:19:51 +0200 Subject: [PATCH] fix(leads): treat social and link-in-bio URLs as no website Many businesses put an Instagram, Facebook or Linktree page in Google's website field. Those leads are the ones without a site of their own, but they were counted as having one. The rule lives in contacts.has_real_website and now backs the Has/No website panel filters, the Website chip, the search option and --require-website, and the "with website" count. The card keeps the link and labels its button "Social". Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 5 +++++ docs/GUIDE.md | 5 ++++- maplead/contacts.py | 41 +++++++++++++++++++++++++++++++++++++- maplead/engine.py | 5 +++-- maplead/gui/app.py | 2 ++ maplead/gui/lead_panel.py | 8 ++++---- maplead/gui/main_window.py | 2 +- 7 files changed, 59 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1a67d8..782bdd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to MAPLEAD. Format follows [Keep a Changelog](https://keepac ## [Unreleased] ### Fixed +- The *No website* filter now includes leads whose website is only a social + profile or link-in-bio page (Instagram, Facebook, Linktree and similar), and + *Has website* leaves them out. Those cards drop the *Website* chip and label + their link button *Social*. *Only leads with a website*, `--require-website` + and the *with website* count follow the same rule. - **Bulk send** no longer crashes the AppImage on newer distros (e.g. Debian 13). The image shipped the build machine's older `libstdc++`, which stopped the system GPU driver from loading, so WhatsApp Web had no OpenGL. The C++ runtime diff --git a/docs/GUIDE.md b/docs/GUIDE.md index cce9bb5..d6fc0c6 100644 --- a/docs/GUIDE.md +++ b/docs/GUIDE.md @@ -170,7 +170,10 @@ reading rather than for a spreadsheet: disappearing. The template is remembered between launches. - **Chips filter the list**: *Has WhatsApp*, *Has phone*, *Has website*, *No website*, *Has e-mail*, *Not contacted*. The search box matches every visible field, and - the sort menu orders by rating, reviews or name. + the sort menu orders by rating, reviews or name. A lead whose website is only a + social profile or link-in-bio page (Instagram, Facebook, Linktree...) counts as + *No website*. The *Only leads with a website* search option and the *with website* + tile use the same rule. - **Copy** on a card puts the whole row (TSV) on the clipboard. - **Right-click a grid row** also has *Send WhatsApp message* and *Open in leads panel*. The panel stays open while you work and refreshes after the next run. diff --git a/maplead/contacts.py b/maplead/contacts.py index f882586..738c9ac 100644 --- a/maplead/contacts.py +++ b/maplead/contacts.py @@ -19,7 +19,7 @@ import datetime import re from typing import Any, Dict, Mapping, Optional, Tuple -from urllib.parse import quote +from urllib.parse import quote, urlsplit from .data import countries as CO @@ -35,6 +35,45 @@ # The demo/outscraper providers may return this sentinel for a nameless place. _UNNAMED = "(unnamed business)" +# Hosts that are a profile page, not a site of the business's own. Many owners +# paste their Instagram or link-in-bio page into Google's "website" field. +# Subdomains (www., m., pt-br.) count as the same host. +_SOCIAL_HOSTS = frozenset({ + "facebook.com", "fb.com", "fb.me", "m.me", + "instagram.com", "instagr.am", "threads.net", "threads.com", + "linkedin.com", "lnkd.in", + "twitter.com", "x.com", "t.co", + "tiktok.com", "kwai.com", "snapchat.com", + "youtube.com", "youtu.be", + "pinterest.com", "pinterest.com.br", "pin.it", + "whatsapp.com", "wa.me", "wa.link", "t.me", "telegram.me", "telegram.org", + # link-in-bio pages + "linktr.ee", "linktree.com", "linkin.bio", "bio.link", "bio.site", "lnk.bio", + "linkr.bio", "tap.bio", "zaap.bio", "campsite.bio", "taplink.cc", "taplink.at", + "taplink.ws", "beacons.ai", "beacons.page", "solo.to", "linkfly.to", + "milkshake.app", "msha.ke", "allmylinks.com", "about.me", "flow.page", + "linkpop.com", "hoo.be", "shor.by", "biolinky.co", +}) + + +def is_social_url(url: Any) -> bool: + """True when ``url`` points at a social network or link-in-bio page.""" + text = str(url or "").strip() + if not text: + return False + try: + host = urlsplit(text if "://" in text else f"https://{text}").hostname + except ValueError: + return False + labels = (host or "").lower().rstrip(".").split(".") + return any(".".join(labels[i:]) in _SOCIAL_HOSTS for i in range(len(labels))) + + +def has_real_website(lead: Mapping[str, Any]) -> bool: + """True when the lead has a website that is not just a social profile.""" + url = str(lead.get("website") or "").strip() + return bool(url) and not is_social_url(url) + DEFAULT_TEMPLATE = ( "Olá {nome}! Tudo bem? Encontrei vocês no Google Maps e gostaria de saber " "mais sobre os serviços de vocês." diff --git a/maplead/engine.py b/maplead/engine.py index 0792820..9e7016e 100644 --- a/maplead/engine.py +++ b/maplead/engine.py @@ -13,6 +13,7 @@ from dataclasses import dataclass, field from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple +from .contacts import has_real_website from .providers import Provider, SearchRequest, SearchResult # --------------------------------------------------------------------------- # @@ -265,7 +266,7 @@ def apply_filters(leads: Sequence[Dict[str, Any]], min_rating: float | None = No if not phone or phone_type(phone, country_code, dial) == "landline": stats["skip_landlines"] += 1 continue - if require_website and not lead.get("website"): + if require_website and not has_real_website(lead): stats["require_website"] += 1 continue if skip_closed and str(lead.get("status", "")).upper().startswith("CLOSED"): @@ -454,7 +455,7 @@ def avg(vals: List[float]) -> float: return { "total": len(leads), "with_phone": sum(1 for l in leads if l.get("phone")), - "with_website": sum(1 for l in leads if l.get("website")), + "with_website": sum(1 for l in leads if has_real_website(l)), "with_email": sum(1 for l in leads if l.get("email")), "avg_rating": avg(ratings), "avg_reviews": avg([float(x) for x in review_totals]), diff --git a/maplead/gui/app.py b/maplead/gui/app.py index 751a3ee..f0ae717 100644 --- a/maplead/gui/app.py +++ b/maplead/gui/app.py @@ -464,6 +464,8 @@ def _selftest_widgets(window) -> bool: ok &= wa_url.startswith("https://wa.me/5511912345678?text=Ol%C3%A1") ok &= contacts.render_template("Olá {nome}!", {}) == "Olá!" ok &= contacts.unknown_placeholders("Oi {bairro}") == ("bairro",) + ok &= not contacts.has_real_website({"website": "https://www.instagram.com/padaria"}) + ok &= contacts.has_real_website({"website": "https://padaria.com.br"}) # --- leads panel: every selected field, filters, paging ---------------- # total = len(window.model.leads) diff --git a/maplead/gui/lead_panel.py b/maplead/gui/lead_panel.py index 97fb03f..152a03b 100644 --- a/maplead/gui/lead_panel.py +++ b/maplead/gui/lead_panel.py @@ -479,8 +479,7 @@ def _precompute(self) -> None: for lead in self._leads] self._has_wa = [bool(contacts.whatsapp_number(lead, dial, iso)) for lead in self._leads] - self._has_site = [bool(str(lead.get("website") or "").strip()) - for lead in self._leads] + self._has_site = [contacts.has_real_website(lead) for lead in self._leads] self._has_email = [bool(str(lead.get("email") or "").strip()) for lead in self._leads] self._contacted = [self._history.was_contacted( @@ -632,7 +631,7 @@ def _url_and_text(self, key: str, text: str, def _presence_chips(self, lead: Dict[str, Any]) -> List[QLabel]: chips: List[QLabel] = [] - if self._has("website") and str(lead.get("website") or "").strip(): + if self._has("website") and contacts.has_real_website(lead): chips.append(chip("Website", "ok")) if self._has("phone") and str(lead.get("phone") or "").strip(): chips.append(chip("Phone", "ok")) @@ -753,7 +752,8 @@ def _card(self, lead: Dict[str, Any], index: int) -> QWidget: shown.add("maps_url") website = str(lead.get("website") or "").strip() if website and self._has("website"): - site_btn = QPushButton("Website") + site_btn = QPushButton( + "Social" if contacts.is_social_url(website) else "Website") site_btn.setProperty("flat", True) site_btn.setIcon(icons.icon("globe", self.p.text_dim, 13)) site_btn.clicked.connect(lambda u=website: self._open_url(u)) diff --git a/maplead/gui/main_window.py b/maplead/gui/main_window.py index f17fd1e..9eec34a 100644 --- a/maplead/gui/main_window.py +++ b/maplead/gui/main_window.py @@ -975,7 +975,7 @@ def pct(part: int) -> str: self.stat_leads.set(str(leads), f"target {self.limit_spin.value()}") self.stat_phone.set(pct(phone), f"{phone} with a number") - self.stat_site.set(pct(site), f"{site} with a URL") + self.stat_site.set(pct(site), f"{site} with a site") self.stat_rating.set(f"{rating:.2f} ★" if rating else "–", "average" if rating else "") self.stat_reviews.set(f"{reviews:,}", "total reviews")