Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. #! /usr/bin/env python3
  2.  
  3. # README on this file in terminal, type "chmod 755 filenamehere.py", and after
  4. # that u can press "./filenamehere.py" to run the program in terminal
  5.  
  6. # code is really good, just could have been a bit shorter to make it prettier
  7. # :)
  8.  
  9. # plus i would reccomend using vim inseatead of nano , its harder to learn but
  10. # is just better, trust me ;)
  11. import praw
  12. import pdb
  13. import re
  14. import os
  15. # no need for password and username file, will find out soon
  16.  
  17. # static variables
  18. likedPosts =r'builds|battlestation|school|college|ascend|ascended|linus|mom'
  19.  
  20. # defined functions
  21.  
  22. # change these arguments as needed u skrub ;)
  23. def flair_search(flair,sreddit,sort_method,search_limit):
  24. # Do a case insensitive search
  25.  
  26. query = r.search(query=flair,subreddit=sreddit,sort=sort_method,limit=search_limit)
  27. for sub in query:
  28. sub.upvote()
  29. print("Bot Upvoting: {}".format(sub))
  30.  
  31. # Create the Reddit instance
  32. # best to put acutal user agent of device here
  33. # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox#Linux
  34. user_agent = ("Harry's memes")
  35. r = praw.Reddit(user_agent=user_agent)
  36.  
  37. # and login
  38. # dont worry u can't be hacked ;) kek
  39. # just added this if u want and make it less glitchy, cbf for now m8
  40. username = input("Username please: ")
  41. password = input("Password please: ")
  42. r.login(username,password)
  43.  
  44. # Have we run this code before? If not, create an empty list
  45. if not os.path.isfile("posts_replied_to.txt"):
  46. posts_replied_to = []
  47.  
  48. # If we have run the code before, load the list of posts we have replied to
  49. else:
  50. # Read the file into a list and remove any empty values
  51. with open("posts_replied_to.txt", "r") as f:
  52. posts_replied_to = f.read()
  53. posts_replied_to = posts_replied_to.split("\n")
  54. posts_replied_to = filter(None, posts_replied_to)
  55.  
  56. # Get the top 5 values from our subreddit
  57. subreddit = r.get_subreddit('pcmasterrace')
  58. for submission in subreddit.get_hot(limit=10):
  59. # If we haven't replied to this post before
  60. if submission.id not in posts_replied_to:
  61.  
  62. flair_search(flair="flair:Battlestation",sreddit="pcmasterrace",sort_method="new",search_limit=10)
  63. flair_search(flair="flair:Build",sreddit="pcmasterrace",sort_method="new",search_limit=10)
  64.  
  65. if re.search(likedPosts, submission.title, re.IGNORECASE):
  66. submission.upvote()
  67. print("Bot upvoting : {}").format(submission.title)
  68. posts_replied_to.append(submission.id)
  69.  
  70. elif re.search("pc's suck", submission.title, re.IGNORECASE):
  71. submission.downvote()
  72. print("Bot Downvoting: {}").format(submission.title)
  73. post_replied_to.append(submission.id)
  74.  
  75. # Write our updated list back to the file
  76. with open("posts_replied_to.txt", "w") as f:
  77. for post_id in posts_replied_to:
  78. f.write(post_id + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement