Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import pickle
- import praw
- from datetime import datetime, timedelta
- from math import ceil
- VERSION = "v0.1.1b"
- MANUAL_FLAIRS = "vanguard", "vexatious", "endorsedflair", "alpha", "betaasfuck", "feeemale"
- print("Hello, Reddit!")
- print("VirtueTron9000 {0} (c) CrashARuntimeToday@outlook.com".format(VERSION))
- reddit = praw.Reddit(client_id="VirtueTron9000",
- client_secret="🤖🤡🍆💯™",
- username="SignalAVirtueToday",
- password="https://youtu.be/RCVJ7bujnSc",
- user_agent="VirtueTron 9000 {0}".format(VERSION))
- class Tracker:
- def __init__(self, name, score, current_flair):
- self.name = name
- self.score = score
- self.smv = None
- self.current_flair = current_flair
- self.next_refresh = datetime.now() + timedelta(minutes=15)
- def calc_score(name):
- NAUGHTY_LIST = "TheRedPill", "MarriedRedPill", "ChristianRedPill","MGTOW","Braincels","AskTRP","AskMRP","RedPillWomen","RedPillWives","CringeAnarchy"
- score = 0
- count = 0
- for comment in reddit.redditor(name).comments.new(limit=100):
- if comment.subreddit.display_name == "TheBluePill":
- score += comment.score - 1
- count += 1
- elif comment.subreddit.display_name in NAUGHTY_LIST and comment.score > 0:
- score -= comment.score
- count += 1
- if count > 0:
- score /= count
- else:
- if score != 0:
- print("WTF? user: {0} has a score of {1} with 0 comments?".format(name, score))
- print("Scanned user: {0}, score is {1} based on {2} comments".format(name, score, count))
- return score
- next_recalc = datetime.now()
- try:
- users = pickle.load(open("users.pickle", "rb"))
- print("Re-loading database")
- except IOError:
- users = {}
- print("I/O error accessing database, starting fresh")
- try:
- for comment in reddit.subreddit("TheBluePill").stream.comments():
- tick = datetime.now()
- if tick > next_recalc:
- print("Recalculating SMV")
- i = 0
- total = len(users)
- for user in sorted(users.values(), key=lambda x: x.score):
- i += 1
- user.smv = ceil((i / total) * 10)
- print("User: {0} has an SMV of {1} with a score of {2} (current flair {3})".format(user.name, user.smv, user.score, user.current_flair))
- if user.current_flair not in MANUAL_FLAIRS and user.current_flair != "hb{0}".format(user.smv):
- print("Setting user: {0} flair to hb{1}".format(user.name, user.smv))
- reddit.subreddit("TheBluePill").flair.set(user.name, "Hβ{0}".format(user.smv), "hb{0}".format(user.smv))
- user.current_flair = "hb{0}".format(user.smv)
- if user.smv > 7:
- if user.name not in reddit.subreddit("TheBluePill").contributor():
- print("Adding approved contributor: {0}".format(user.name))
- reddit.subreddit("TheBluePill").contributor.add(user.name)
- elif user.smv < 4:
- if user.name in reddit.subreddit("TheBluePill").contributor():
- print("Removing approved contributor: {0}".format(user.name))
- reddit.subreddit("TheBluePill").contributor.remove(user.name)
- elif user.current_flair in MANUAL_FLAIRS:
- print("Not changing manual flair '{0}' for user {1}".format(user.current_flair, user.name))
- else:
- print("User: {0} still an HB{1}".format(user.name, user.smv))
- next_recalc = tick + timedelta(minutes=15)
- pickle.dump(users, open("users.pickle", "wb"))
- print("Next refresh: {0}".format(next_recalc))
- name = comment.author.name
- if not name in users.keys() or tick > users[name].next_refresh:
- users[name] = Tracker(name, calc_score(name), comment.author_flair_css_class)
- else:
- print("Skipping score update for user:{0}, not due for refresh".format(name))
- if comment.author_flair_css_class != users[name].current_flair:
- print("Updating tracked flair for user:{0} -- old: {1}, new {2}".format(name, users[name].current_flair, comment.author_flair_css_class))
- except KeyboardInterrupt:
- print("VirtuteTron going off-line")
- pickle.dump(users, open("users.pickle", "wb"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement