generate_seed.py 8.47 KB
import json
import random
from datetime import datetime, timezone

subreddits = {
    "AmITheAsshole": {
        "templates": [
            ("AITA for telling my {relation} that their {obj} is {adj}?", "My {relation} has this {obj} that they treasure...", "moral_dilemma"),
            ("WIBTA if I {action} at {event}?", "I (28F) have been planning this for months...", "social_conflict"),
            ("AITA for refusing to {action} for my {relation}?", "So here's the situation. I work full time...", "boundary_setting"),
        ],
        "relation": ["sister", "brother", "mother-in-law", "roommate", "coworker", "best friend", "aunt", "stepmom"],
        "obj": ["wedding dress", "cooking", "new car", "baby name", "house rules", "diet", "hobby", "opinion"],
        "adj": ["ugly", "unhealthy", "inappropriate", "overpriced", "ridiculous", "embarrassing"],
        "action": ["skip the wedding", "speak up", "move out", "call the police", "refuse to apologize", "quit the group chat"],
        "event": ["the family dinner", "the wedding", "the work meeting", "Thanksgiving", "the baby shower", "the funeral"],
    },
    "relationship_advice": {
        "templates": [
            ("My ({age}M) partner ({age2}F) {action} and I don't know how to feel", "We've been together for {years} years...", "trust_issue"),
            ("I think my {relation} is {action}, what should I do?", "I found some messages on their phone...", "betrayal"),
            ("How do I tell my {relation} that I {feeling} without hurting them?", "This has been weighing on me for months...", "communication"),
        ],
        "relation": ["boyfriend", "girlfriend", "husband", "wife", "fiancé", "partner of 3 years"],
        "action": ["cheating on me", "lying about their job", "keeping texting their ex", "not wanting kids", "wanting to move across the country"],
        "feeling": ["want to break up", "don't love them anymore", "need space", "am not attracted to them"],
    },
    "funny": {
        "templates": [
            ("{subject} {action} and I can't stop laughing", "So this just happened at work...", "observational_humor"),
            ("My {subject} {action}. That's it. That's the post.", "No context needed.", "absurdist"),
            ("Who else remembers {thing}?", "Found this gem in my grandparents' attic.", "nostalgia"),
        ],
        "subject": ["my cat", "my boss", "this random dude", "my grandma", "the delivery guy", "an AI"],
        "action": ["tried to parallel park", "fell asleep in a meeting", "sent me a meme at 3am", "dressed up as a banana"],
        "thing": ["floppy disks", "dial-up internet", "Blockbuster", "Tamagotchis", "Nokia phones"],
    }
}

def rand_date():
    now = datetime.now(timezone.utc)
    delta = random.randint(0, 604800)
    return (now.timestamp() - delta)

def generate_post(subreddit, idx):
    cfg = subreddits[subreddit]
    tpl = random.choice(cfg["templates"])
    title_template, body_template, conflict_type = tpl

    kwargs = {}
    for k, v in cfg.items():
        if k != "templates":
            kwargs[k] = random.choice(v)

    if subreddit == "relationship_advice":
        age = random.randint(22, 38)
        age2 = age + random.randint(-3, 5)
        years = random.randint(1, 8)
        kwargs["age"] = age
        kwargs["age2"] = age2
        kwargs["years"] = years

    title = title_template.format(**kwargs)
    body = body_template.format(**kwargs)
    if random.random() > 0.5:
        body += "\n\nEdit: Thanks for the responses."

    score = random.randint(500, 45000) if subreddit != "funny" else random.randint(1200, 85000)
    num_comments = int(score * random.uniform(0.05, 0.45))
    upvote_ratio = round(random.uniform(0.72, 0.98), 2)

    post_id = f"{subreddit[:3].lower()}{random.randint(100000, 999999)}"
    created_ts = rand_date()

    if subreddit == "AmITheAsshole":
        characters = [
            {"role": "Protagonist", "archetype": "conflicted everyman"},
            {"role": "Antagonist", "archetype": random.choice(["entitled relative", "oblivious coworker", "demanding in-law"])}
        ]
    elif subreddit == "relationship_advice":
        characters = [
            {"role": "OP", "archetype": "betrayed partner"},
            {"role": "Partner", "archetype": random.choice(["secretive lover", "commitment-phobe", "gaslighter"])}
        ]
    else:
        characters = [
            {"role": "Subject", "archetype": random.choice(["clueless boomer", "chaotic pet", "absurdist everyman"])}
        ]

    setting = random.choice([
        "domestic living room", "office conference room", "family dinner table",
        "car on highway", "wedding venue", "hospital waiting room", "grocery store"
    ])
    conflict = random.choice([
        "lies exposed at the worst moment",
        "boundary crossed for the final time",
        "social faux pas escalates",
        "unexpected third party intervenes",
        "secret revealed through technology"
    ])
    dialogue = random.choice([
        '"You should have told me the truth."',
        '"I can\'t believe you did that in front of everyone."',
        '"This is exactly why I never wanted to come here."',
        '"If you really loved me, you would have known."',
        '"I was just trying to help!"'
    ])
    twist = random.choice([
        "The innocent party was actually complicit",
        "A misunderstanding spiraled because of group chat",
        "The villain had a tragic backstory",
        "Technology (phone/AI) accidentally revealed everything"
    ])
    emotion_arc = random.choice([
        "resentment → shock → righteous anger",
        "confusion → suspicion → devastation → resolve",
        "amusement → absurdity → viral catharsis",
        "embarrassment → defensiveness → reluctant acceptance"
    ])

    base_drama = (min(score, 20000) / 20000) * 30 + upvote_ratio * 20
    comment_density = min(num_comments / 500, 20)
    conflict_bonus = {
        "moral_dilemma": 12, "social_conflict": 10, "boundary_setting": 8,
        "trust_issue": 14, "betrayal": 16, "communication": 6,
        "observational_humor": 4, "absurdist": 5, "nostalgia": 3
    }.get(conflict_type, 5)
    drama_score = round(base_drama + comment_density + conflict_bonus + random.uniform(-2, 2), 1)
    drama_score = max(0, min(100, drama_score))

    permalink = f"/r/{subreddit}/comments/{post_id}/"

    return {
        "post_id": post_id,
        "source": {
            "platform": "reddit",
            "subreddit": subreddit,
            "permalink": permalink,
            "source_url": f"https://www.reddit.com{permalink}",
            "crawl_time": datetime.now(timezone.utc).isoformat()
        },
        "engagement": {
            "score": score,
            "num_comments": num_comments,
            "upvote_ratio": upvote_ratio,
            "awards": random.randint(0, 12)
        },
        "content": {
            "title": title,
            "body": body,
            "author": f"u/throwaway_{random.randint(1000,9999)}",
            "created_utc": created_ts,
            "is_nsfw": False,
            "is_spoiler": False
        },
        "drama_elements": {
            "characters": characters,
            "setting": setting,
            "conflict_type": conflict_type,
            "conflict_summary": conflict,
            "key_dialogue": dialogue,
            "plot_twist": twist,
            "emotion_arc": emotion_arc
        },
        "script_potential": {
            "drama_score": drama_score,
            "genre_suggestion": random.choice([
                "domestic drama", "romantic tragedy", "office comedy",
                "family feud", "tiktok skit", "reveal video"
            ]),
            "estimated_duration_sec": random.choice([30, 45, 60, 90, 120]),
            "visual_hooks": random.sample([
                "reaction shot", "text message reveal", "door slam",
                "zoom on face", "split screen argument", "flashback montage",
                "overheard conversation", "public meltdown"
            ], k=3),
            "target_demographics": random.choice([
                ["18-24F", "25-34F"],
                ["18-24M", "18-24F"],
                ["25-34 All"],
                ["13-17 All"]
            ])
        }
    }

random.seed(42)
posts = []
for sub in ["AmITheAsshole", "relationship_advice", "funny"]:
    count = 16 if sub == "funny" else 17
    for i in range(count):
        posts.append(generate_post(sub, i))

random.shuffle(posts)

with open("seed_data.json", "w", encoding="utf-8") as f:
    json.dump(posts, f, ensure_ascii=False, indent=2)

print(f"Generated {len(posts)} seed posts")