Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw, random, textwrap, yaml, pytz
- from datetime import datetime, timezone, timedelta
- # Load config
- with open("config.yaml") as f:
- c = yaml.safe_load(f)
- reddit = praw.Reddit(
- client_id=c["client_id"],
- client_secret=c["client_secret"],
- user_agent=c["user_agent"],
- )
- sub = reddit.submission(url=c["post_url"])
- sub.comments.replace_more(limit=None)
- comments = [cm for cm in sub.comments if hasattr(cm, "body")]
- now = datetime.now(timezone.utc)
- min_age = timedelta(days=c.get("min_account_age_days", 3))
- keyword = c.get("required_keyword", "gabagool").lower()
- packs = c.get("packs", [])
- # Build author age map
- age_map = {}
- for cm in comments:
- if cm.author and cm.author.name not in age_map:
- age_map[cm.author.name] = now - datetime.fromtimestamp(
- cm.author.created_utc, timezone.utc
- )
- # Filter valid entries
- valid = [
- cm
- for cm in comments
- if cm.author
- and keyword in cm.body.lower()
- and age_map.get(cm.author.name, timedelta()) >= min_age
- ]
- if len(valid) < c.get("num_winners", 2):
- print(f"โ ๏ธ Not enough valid entries โ found {len(valid)}.")
- exit(1)
- winners = random.sample(valid, k=c["num_winners"])
- # Output
- et = now.astimezone(pytz.timezone("US/Eastern")).strftime("%B %d at %-I:%M %p ET")
- cest = now.astimezone(pytz.timezone("Europe/Berlin")).strftime("%-I:%M %p CEST")
- print("\n" + "=" * 60)
- print("๐ V RISING DLC RAFFLE RESULTS ๐".center(60))
- print("=" * 60)
- print(f"โฐ Draw Time: {et} / {cest}\n")
- print(
- f"๐งพ Filter: Only top-level comments containing '{keyword}' from accounts at least {min_age.days} days old.\n"
- )
- for i, w in enumerate(winners):
- age = int(age_map[w.author.name].days)
- print(f"๐ Winner #{i+1}:")
- print(f"๐ค Reddit User: u/{w.author.name} (Account Age: {age} days)")
- print(f"๐ Awarded: {packs[i]}")
- print("๐จ๏ธ Comment:")
- print(
- textwrap.fill(
- w.body.strip(), width=60, initial_indent=" ", subsequent_indent=" "
- )
- )
- print("\n" + "-" * 60 + "\n")
- print("โ Winners will be contacted via Reddit DM")
- print("๐ Thank you to everyone who entered โ stay undead! ๐ฆ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement