#!/usr/bin/env python3
import requests
import json

url = 'https://www.reddit.com/r/programming/search.json?q=code+review&sort=new&limit=10'
headers = {'User-Agent': 'Mozilla/5.0'}

response = requests.get(url, headers=headers, timeout=10)
data = response.json()

posts = data.get('data', {}).get('children', [])
print(f"Found {len(posts)} posts from Reddit\n")

for i, post in enumerate(posts[:5]):
    p = post.get('data', {})
    print(f"\nPost {i+1}:")
    print(f"  Title: {p.get('title', '')[:80]}")
    print(f"  Text: {p.get('selftext', '')[:100]}")
    print(f"  Score: {p.get('score', 0)}")
    print(f"  Comments: {p.get('num_comments', 0)}")
