-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_to_csv.py
More file actions
55 lines (42 loc) · 1.52 KB
/
Copy pathexport_to_csv.py
File metadata and controls
55 lines (42 loc) · 1.52 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
"""
Export ProductHunt products to CSV.
export APIFY_API_TOKEN=apify_api_xxxxxx
python examples/export_to_csv.py > products.csv
"""
import csv
import sys
from producthunt_scraper import ProductHuntScraperClient
PRODUCTS = [
"https://www.producthunt.com/posts/chatgpt",
"https://www.producthunt.com/posts/notion",
"https://www.producthunt.com/posts/midjourney",
]
COLUMNS = [
"productName", "tagline", "website", "upvotes", "commentsCount",
"reviewsCount", "rating", "followers", "topicsStr", "makersStr",
"pricing", "pricingTier", "isFeatured", "launchDate",
"dailyRank", "weeklyRank", "popularityScore", "maturityTier",
"daysSinceLaunch", "isNewProduct", "upvoteVelocity", "engagementRate",
"techStackSignals", "sentimentScore", "hasSocialProof",
"badges", "dataSource", "productUrl",
]
def flatten(rec: dict) -> dict:
out = {}
for col in COLUMNS:
v = rec.get(col)
if isinstance(v, list):
v = "; ".join(str(x) for x in v)
elif isinstance(v, dict):
v = str(v)
out[col] = v if v is not None else ""
return out
def main() -> None:
client = ProductHuntScraperClient()
results = client.analyze(PRODUCTS)
writer = csv.DictWriter(sys.stdout, fieldnames=COLUMNS)
writer.writeheader()
for r in results:
if r.get("success") and r.get("dataType") != "competitor_analysis":
writer.writerow(flatten(r))
if __name__ == "__main__":
main()