Advertisement
Guest User

instant_vote_score_changes.py

a guest
Mar 21st, 2016
2,513
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import praw
  2. import time
  3. import os
  4.  
  5. os.environ['TZ'] = 'UTC'
  6. time.tzset()
  7.  
  8. def login():
  9.     # You'll need to use your own login credentials
  10.  
  11. r = login()
  12. subreddit = r.get_subreddit('bitcoin') # needs to be subreddits that you moderate, or that doesn't temporarily hide vote scores.
  13.  
  14. timeframeNewest = (60*0)
  15. timeframeOldest = (60*3) # release comments older than 3 minutes
  16.  
  17. commentIDs_downvoted = []
  18. commentIDs_upvoted = []
  19. targeted_downvotes = []
  20. targeted_upvotes = []
  21. preprocessed = []
  22.  
  23. # ignore comments made before script was started
  24. new_comments = subreddit.get_comments(limit=10)
  25. for comment in new_comments:
  26.     preprocessed.append(comment.id)
  27.  
  28. def get_comments(subreddit):
  29.     new_comments = subreddit.get_comments(limit=10) # increase this if the sub gets more than 10 comments in 3 minutes
  30.     for comment in new_comments:
  31.         if comment.id not in commentIDs_downvoted and comment.id not in commentIDs_upvoted and comment.id not in preprocessed:
  32.             now = int(time.time())
  33.             comment_score = comment.ups - comment.downs
  34.             if (now - timeframeOldest) < comment.created_utc < (now - timeframeNewest) and comment_score < 1:
  35.                 comment_age = time.time() - comment.created_utc
  36.                 print comment_score, comment_age, time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(comment.created_utc)), comment.author, comment.permalink
  37.                 commentIDs_downvoted.append(comment.id)
  38.                 if str(comment.author) not in targeted_downvotes:
  39.                     targeted_downvotes.append(str(comment.author))
  40.             elif (now - timeframeOldest) < comment.created_utc < (now - timeframeNewest) and comment_score > 1:
  41.                 comment_age = time.time() - comment.created_utc
  42.                 print comment_score, comment_age, time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(comment.created_utc)), comment.author, comment.permalink
  43.                 commentIDs_upvoted.append(comment.id)
  44.                 if str(comment.author) not in targeted_upvotes:
  45.                     targeted_upvotes.append(str(comment.author))
  46.  
  47. while True:
  48.     while True:
  49.         try:
  50.             get_comments(subreddit)
  51.             time.sleep(2)
  52.         except:
  53.             print "crashed..."
  54.             continue
  55.         break
Advertisement
RAW Paste Data Copied
Advertisement