DEV Community

agenthustler
agenthustler

Posted on

How to Build a Social Proof Aggregator: Track Mentions Across Twitter, Reddit, and HN

Social proof drives conversions. Aggregate product mentions from Reddit and HN automatically.

Reddit Search

import requests
from bs4 import BeautifulSoup
import time
from datetime import datetime, timedelta

class SocialProof:
    def __init__(self, keywords):
        self.kw = keywords
        self.mentions = []
        self.s = requests.Session()
        self.s.headers["User-Agent"] = "SocialProofBot/1.0"

    def reddit(self, limit=100):
        found = []
        for kw in self.kw:
            r = self.s.get("https://www.reddit.com/search.json",
                params={"q":kw,"sort":"new","limit":min(limit,100),"t":"month"})
            if r.status_code != 200: continue
            for p in r.json().get("data",{}).get("children",[]):
                d = p["data"]
                found.append({"platform":"reddit","text":d.get("title",""),
                    "url":f"https://reddit.com{d.get('permalink','')}",
                    "score":d.get("score",0),
                    "date":datetime.fromtimestamp(d["created_utc"]).isoformat()})
            time.sleep(1)
        return found

    def hn(self, limit=50):
        found = []
        for kw in self.kw:
            r = self.s.get("https://hn.algolia.com/api/v1/search",
                params={"query":kw,"tags":"(story,comment)","hitsPerPage":limit,
                    "numericFilters":f"created_at_i>{int((datetime.now()-timedelta(days=30)).timestamp())}"})
            for h in r.json().get("hits",[]):
                text = h.get("title") or h.get("comment_text","")
                if "<" in text: text = BeautifulSoup(text,"html.parser").get_text()
                if text: found.append({"platform":"hn","text":text[:300],
                    "url":f"https://news.ycombinator.com/item?id={h['objectID']}",
                    "score":h.get("points",0) or 0})
            time.sleep(0.5)
        return found

    def sentiment(self, text):
        t = text.lower()
        p = sum(1 for w in ["love","great","amazing","best","recommend","awesome"] if w in t)
        n = sum(1 for w in ["hate","terrible","worst","avoid","broken","scam"] if w in t)
        return "positive" if p>n else ("negative" if n>p else "neutral")

    def run(self):
        self.mentions = self.reddit() + self.hn()
        for m in self.mentions: m["sent"] = self.sentiment(m["text"])
        self.mentions.sort(key=lambda x:x.get("score",0), reverse=True)
        sent = {"positive":0,"negative":0,"neutral":0}
        for m in self.mentions: sent[m["sent"]] += 1
        print(f"{len(self.mentions)} mentions | +{sent['positive']} ~{sent['neutral']} -{sent['negative']}")
        for m in [m for m in self.mentions if m["sent"]=="positive"][:5]:
            print(f"  [{m['platform']}] {m['text'][:80]}")

SocialProof(["your-product"]).run()
Enter fullscreen mode Exit fullscreen mode

Scaling

ScraperAPI handles rate limits. ThorData for IP rotation. ScrapeOps monitors jobs.

Display

Power landing page widgets with aggregated mentions. Real-time social proof converts better than testimonials.

Top comments (0)