| import gradio as gr |
| import praw |
| import re |
|
|
| |
| REDDIT_CLIENT_ID = "pWkYNUvj3o3wsqiOiki8Zg" |
| REDDIT_CLIENT_SECRET = "1f85lA8fvBVY9L2BThpp4VHa92rcCw" |
| REDDIT_USER_AGENT = "wuhp web app by u/wuhp24" |
| |
|
|
| reddit = praw.Reddit( |
| client_id=REDDIT_CLIENT_ID, |
| client_secret=REDDIT_CLIENT_SECRET, |
| user_agent=REDDIT_USER_AGENT, |
| check_for_async=False |
| ) |
|
|
| def extract_post_id(url: str) -> str: |
| match = re.search(r"comments/([a-z0-9]+)/", url) |
| if not match: |
| raise ValueError("Invalid Reddit post URL") |
| return match.group(1) |
|
|
| def fetch_entries(url): |
| try: |
| submission = reddit.submission(id=extract_post_id(url)) |
| submission.comments.replace_more(limit=None) |
|
|
| op_username = str(submission.author) |
| seen_users = {} |
|
|
| for comment in submission.comments.list(): |
| if comment.author is None: |
| continue |
|
|
| username = str(comment.author) |
|
|
| |
| if username.lower() == "automoderator": |
| continue |
| if username == op_username: |
| continue |
|
|
| |
| if username not in seen_users: |
| seen_users[username] = comment.body.strip() |
|
|
| if not seen_users: |
| return "", "", "β οΈ No valid entries found." |
|
|
| |
| with_comments = [] |
| for user, comment in seen_users.items(): |
| with_comments.append(f"{user}: {comment}") |
|
|
| with_comments_text = "\n".join(with_comments) |
|
|
| |
| names_only_text = "\n".join(seen_users.keys()) |
|
|
| status = f"π Total valid entries: {len(seen_users)}" |
|
|
| return with_comments_text, names_only_text, status |
|
|
| except Exception as e: |
| return "", "", f"β Error: {e}" |
|
|
| |
| with gr.Blocks() as demo: |
| gr.Markdown("# π Reddit Giveaway Entry Extractor") |
| gr.Markdown( |
| "- Uses Reddit official API\n" |
| "- One entry per user\n" |
| "- Excludes AutoModerator & OP\n" |
| "- Output is wheel-site ready (transparent & fair)" |
| ) |
|
|
| url_input = gr.Textbox( |
| label="Reddit Post URL", |
| placeholder="Paste Reddit post URL here" |
| ) |
|
|
| fetch_btn = gr.Button("Fetch Entries") |
|
|
| comments_output = gr.Textbox( |
| label="Entries (Username + Comment)", |
| lines=18 |
| ) |
|
|
| names_output = gr.Textbox( |
| label="Entries (Usernames Only β Paste Into Wheel)", |
| lines=18 |
| ) |
|
|
| status_output = gr.Textbox(label="Status") |
|
|
| fetch_btn.click( |
| fetch_entries, |
| inputs=url_input, |
| outputs=[comments_output, names_output, status_output] |
| ) |
|
|
| demo.launch() |
|
|