-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopic_research.py
More file actions
77 lines (58 loc) · 2.49 KB
/
Copy pathtopic_research.py
File metadata and controls
77 lines (58 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Topic research: top products in a category with tech stack analysis.
Useful for:
- Understanding what tools dominate a niche
- Finding gaps in the market
- Competitive landscape mapping
Requires ProductHunt API credentials.
export APIFY_API_TOKEN=apify_api_xxxxxx
export PH_CLIENT_ID=your_ph_client_id
export PH_CLIENT_SECRET=your_ph_client_secret
python examples/topic_research.py
"""
from collections import Counter
from producthunt_scraper import ProductHuntScraperClient
TOPIC = "artificial-intelligence" # Try: developer-tools, productivity, design-tools
def main() -> None:
client = ProductHuntScraperClient()
print(f"Fetching top 50 products in topic: {TOPIC}")
products = client.topic_products(
TOPIC,
limit=50,
order="VOTES",
include_competitor_analysis=True,
)
# Separate analysis record
analysis = next((p for p in products if p.get("dataType") == "competitor_analysis"), None)
products = [p for p in products if p.get("success")]
print(f"\n=== Topic: {TOPIC} ({len(products)} products) ===\n")
# Tech stack distribution
tech_counter = Counter()
for p in products:
for t in (p.get("techStackSignals") or []):
tech_counter[t] += 1
print("Tech stack distribution:")
for tech, count in tech_counter.most_common(10):
pct = count / len(products) * 100
bar = "█" * int(pct / 5)
print(f" {tech:<25} {bar:<20} {count}/{len(products)} ({pct:.0f}%)")
# Pricing distribution
pricing_counter = Counter(p.get("pricingTier", "unknown") for p in products)
print(f"\nPricing distribution:")
for tier, count in pricing_counter.most_common():
print(f" {tier:<15} {count}")
# Top 5 by upvotes
top5 = sorted(products, key=lambda p: p.get("upvotes") or 0, reverse=True)[:5]
print(f"\nTop 5 by upvotes:")
for i, p in enumerate(top5, 1):
print(f" {i}. {p.get('productName', '?'):<35} "
f"{p.get('upvotes') or 0:>6,} upvotes "
f"score={p.get('popularityScore')}")
if analysis:
print(f"\nCompetitor analysis summary:")
print(f" Avg upvotes: {analysis.get('avgUpvotes')}")
print(f" Avg rating: {analysis.get('avgRating')}")
print(f" New products: {analysis.get('newProducts')}")
print(f" Featured: {analysis.get('featuredProducts')}")
if __name__ == "__main__":
main()