Advertisement
Guest User

VirtueTron9000 v0.1.1

a guest
Jun 26th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.50 KB | None | 0 0
  1. #!/usr/bin/python
  2. import pickle
  3. import praw
  4. from datetime import datetime, timedelta
  5. from math import ceil
  6.  
  7. MANUAL_FLAIRS = "vanguard", "vexatious", "endorsedflair", "alpha", "betaasfuck", "feeemale"
  8.  
  9. print("Hello, Reddit!")
  10. print("VirtueTron9000 v0.1.1 (c) CrashARuntimeToday@outlook.com")
  11.  
  12. reddit = praw.Reddit(client_id="VirtueTron9000",
  13.                      client_secret="🤖🤡🍆💯™",
  14.                      username="SignalAVirtueToday",
  15.                      password="https://youtu.be/RCVJ7bujnSc",
  16.                      user_agent="VirtueTron 9000 v0.1.1")
  17.  
  18. class Tracker:
  19.     def __init__(self, name, score, current_flair):
  20.         self.name = name
  21.         self.score = score
  22.         self.smv = None
  23.         self.current_flair = current_flair
  24.         now = datetime.now()
  25.         self.next_refresh = now + timedelta(minutes=15)
  26.  
  27. def calc_score(name):
  28.     NAUGHTY_LIST = "TheRedPill", "MarriedRedPill", "ChristianRedPill","MGTOW","Braincels","AskTRP","AskMRP","RedPillWomen","RedPillWives","CringeAnarchy"
  29.     score = 0
  30.     count = 0
  31.     for comment in reddit.redditor(name).comments.new(limit=100):
  32.         if comment.subreddit.display_name == "TheBluePill":
  33.             score += comment.score - 1
  34.             count += 1
  35.         elif comment.subreddit.display_name in NAUGHTY_LIST:
  36.             if comment.score > 0:
  37.                 score -= comment.score
  38.                 count += 1
  39.     if count > 0:
  40.         score /= count
  41.     else:
  42.         if score != 0:
  43.             print("WTF? user: {0} has a score of {1} with 0 comments?".format(name, score))
  44.     print("Scanned user: {0}, score is {1} based on {2} comments".format(name, score, count))
  45.     return score
  46.  
  47.  
  48. next_recalc = datetime.now()
  49. try:
  50.     users = pickle.load(open("users.pickle", "rb"))
  51.     print("Re-loading database")
  52. except IOError:
  53.     users = {}
  54.     print("I/O error accessing database, starting fresh")
  55.  
  56.  
  57. try:
  58.     for comment in reddit.subreddit("TheBluePill").stream.comments():
  59.         tick = datetime.now()
  60.         if tick > next_recalc:
  61.             print("Recalculating SMV")
  62.             i = 0
  63.             total = len(users)
  64.             for user in sorted(users.values(), key=lambda x: x.score):
  65.                 i += 1
  66.                 user.smv = ceil((i / total) * 10)
  67.                 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))
  68.  
  69.                 if user.current_flair not in MANUAL_FLAIRS and user.current_flair != "hb{0}".format(user.smv):
  70.                     print("Setting user: {0} flair to hb{1}".format(user.name, user.smv))
  71.                     reddit.subreddit("TheBluePill").flair.set(user.name, "Hβ{0}".format(user.smv), "hb{0}".format(user.smv))
  72.                     user.current_flair = "hb{0}".format(user.smv)
  73.                     if user.smv > 7:
  74.                         if user.name not in reddit.subreddit("TheBluePill").contributor():
  75.                             print("Adding approved contributor: {0}".format(user.name))
  76.                             reddit.subreddit("TheBluePill").contributor.add(user.name)
  77.                     elif user.smv < 4:
  78.                         if user.name in reddit.subreddit("TheBluePill").contributor():
  79.                             print("Removing approved contributor: {0}".format(user.name))
  80.                             reddit.subreddit("TheBluePill").contributor.remove(user.name)
  81.                 elif user.current_flair in MANUAL_FLAIRS:
  82.                     print("Not changing manual flair '{0}' for user {1}".format(user.current_flair, user.name))
  83.                 else:
  84.                     print("User: {0} still an HB{1}".format(user.name, user.smv))
  85.  
  86.             next_recalc = tick + timedelta(minutes=15)
  87.             pickle.dump(users, open("users.pickle", "wb"))
  88.             print("Next refresh: {0}".format(next_recalc))
  89.  
  90.         name = comment.author.name
  91.         if not name in users.keys() or tick > users[name].next_refresh:
  92.             users[name] = Tracker(name, calc_score(name), comment.author_flair_css_class)
  93.         else:
  94.             print("Skipping score update for user:{0}, not due for refresh".format(name))
  95.             if comment.author_flair_css_class != users[name].current_flair:
  96.                 print("Updating tracked flair for user:{0} -- old: {1}, new {2}".format(name, users[name].current_flair, comment.author_flair_css_class))
  97. except KeyboardInterrupt:
  98.     print("VirtuteTron going off-line")
  99.     pickle.dump(users, open("users.pickle", "wb"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement