Advertisement
Guest User

VirtueTron9000 v0.1.1b

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