Shell
#!/usr/bin/env python3
"""
Reddit Goldmine Thread Finder
Searches subreddits for high-value market research threads.
Usage:
python find_goldmine_threads.py <subreddit> [--query "search terms"]
python find_goldmine_threads.py SaaS --query "wish existed"
python find_goldmine_threads.py smallbusiness
Finds threads with high engagement that reveal:
- Pain points and frustrations
- Product requests and gaps
- Buying signals
- Competitor discussions
"""
import json
import subprocess
import sys
import urllib.parse
from datetime import datetime
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
# High-value search queries for market research
GOLDMINE_QUERIES = [
"wish existed",
"hate about",
"frustrating",
"looking for",
"recommend",
"alternative to",
"switched from",
"anyone using",
"what software",
"how do you",
"best tool for",
"paying for",
"waste of money",
"game changer",
"changed my life",
]
def fetch_json(url: str) -> dict:
"""Fetch URL as JSON using curl."""
result = subprocess.run(
['curl', '-s', '-A', USER_AGENT, url],
capture_output=True,
text=True,
timeout=30
)
if result.returncode != 0 or not result.stdout:
raise Exception(f"curl failed: {result.stderr or 'empty response'}")
try:
return json.loads(result.stdout)
except json.JSONDecodeError as e:
raise Exception(f"Invalid JSON response: {e}")
def search_subreddit(subreddit: str, query: str = None, sort: str = "top", time: str = "year", limit: int = 25) -> list:
"""Search a subreddit for threads."""
if query:
encoded_query = urllib.parse.quote(query)
url = f"https://www.reddit.com/r/{subreddit}/search.json?q={encoded_query}&restrict_sr=1&sort={sort}&t={time}&limit={limit}"
else:
url = f"https://www.reddit.com/r/{subreddit}/{sort}.json?t={time}&limit={limit}"
data = fetch_json(url)
threads = []
for post in data.get('data', {}).get('children', []):
p = post['data']
threads.append({
'title': p.get('title', ''),
'score': p.get('score', 0),
'num_comments': p.get('num_comments', 0),
'upvote_ratio': p.get('upvote_ratio', 0),
'url': f"https://reddit.com{p.get('permalink', '')}",
'created_utc': p.get('created_utc'),
'author': p.get('author', '[deleted]'),
'selftext_preview': p.get('selftext', '')[:200],
'flair': p.get('link_flair_text'),
})
return threads
def calculate_goldmine_score(thread: dict) -> float:
"""Calculate how valuable a thread is for market research."""
score = 0
# High comment count = lots of discussion
score += min(thread['num_comments'] / 10, 20) # Up to 20 pts
# Good upvote ratio = quality content
score += thread['upvote_ratio'] * 10 # Up to 10 pts
# Post score indicates visibility
score += min(thread['score'] / 50, 10) # Up to 10 pts
# Bonus for certain keywords in title
title_lower = thread['title'].lower()
goldmine_keywords = ['wish', 'hate', 'love', 'best', 'worst', 'looking for',
'recommend', 'help', 'advice', 'alternative', 'switched',
'paying', 'worth it', 'frustrat', 'problem', 'solution']
for kw in goldmine_keywords:
if kw in title_lower:
score += 3
return round(score, 2)
def main():
if len(sys.argv) < 2:
print("Usage: python find_goldmine_threads.py <subreddit> [--query \"search terms\"]")
print("\nExamples:")
print(" python find_goldmine_threads.py SaaS")
print(" python find_goldmine_threads.py smallbusiness --query \"software\"")
print(" python find_goldmine_threads.py entrepreneur --query \"wish existed\"")
sys.exit(1)
subreddit = sys.argv[1]
query = None
# Parse --query argument
if '--query' in sys.argv:
idx = sys.argv.index('--query')
if idx + 1 < len(sys.argv):
query = sys.argv[idx + 1]
print(f"π Scanning r/{subreddit}" + (f" for '{query}'" if query else ""))
print("=" * 70)
all_threads = []
if query:
# Single search
threads = search_subreddit(subreddit, query)
all_threads.extend(threads)
else:
# Multiple goldmine searches
print(f"Running {len(GOLDMINE_QUERIES)} goldmine queries...")
for gq in GOLDMINE_QUERIES:
try:
threads = search_subreddit(subreddit, gq, limit=10)
all_threads.extend(threads)
print(f" β '{gq}': {len(threads)} threads")
except Exception as e:
print(f" β '{gq}': {e}")
# Deduplicate by URL
seen_urls = set()
unique_threads = []
for t in all_threads:
if t['url'] not in seen_urls:
seen_urls.add(t['url'])
t['goldmine_score'] = calculate_goldmine_score(t)
unique_threads.append(t)
# Sort by goldmine score
unique_threads.sort(key=lambda x: x['goldmine_score'], reverse=True)
print(f"\nπ TOP {min(20, len(unique_threads))} GOLDMINE THREADS")
print("=" * 70)
for i, t in enumerate(unique_threads[:20], 1):
print(f"\n{i}. [Score: {t['goldmine_score']}] {t['title'][:70]}")
print(f" π {t['score']} pts | π¬ {t['num_comments']} comments | π {t['upvote_ratio']:.0%}")
print(f" π {t['url']}")
# Save results
output_file = f"goldmine_{subreddit}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
with open(output_file, 'w') as f:
json.dump({
'subreddit': subreddit,
'query': query,
'scanned_at': datetime.now().isoformat(),
'threads': unique_threads
}, f, indent=2)
print(f"\nπΎ Saved {len(unique_threads)} threads to: {output_file}")
print("\nNext: Run `python analyze_thread.py <url>` on any thread above")
if __name__ == '__main__':
main()