Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- # README on this file in terminal, type "chmod 755 filenamehere.py", and after
- # that u can press "./filenamehere.py" to run the program in terminal
- # code is really good, just could have been a bit shorter to make it prettier
- # :)
- # plus i would reccomend using vim inseatead of nano , its harder to learn but
- # is just better, trust me ;)
- import praw
- import pdb
- import re
- import os
- # no need for password and username file, will find out soon
- # static variables
- likedPosts =r'builds|battlestation|school|college|ascend|ascended|linus|mom'
- # defined functions
- # change these arguments as needed u skrub ;)
- def flair_search(flair,sreddit,sort_method,search_limit):
- # Do a case insensitive search
- query = r.search(query=flair,subreddit=sreddit,sort=sort_method,limit=search_limit)
- for sub in query:
- sub.upvote()
- print("Bot Upvoting: {}".format(sub))
- # Create the Reddit instance
- # best to put acutal user agent of device here
- # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox#Linux
- user_agent = ("Harry's memes")
- r = praw.Reddit(user_agent=user_agent)
- # and login
- # dont worry u can't be hacked ;) kek
- # just added this if u want and make it less glitchy, cbf for now m8
- username = input("Username please: ")
- password = input("Password please: ")
- r.login(username,password)
- # Have we run this code before? If not, create an empty list
- if not os.path.isfile("posts_replied_to.txt"):
- posts_replied_to = []
- # If we have run the code before, load the list of posts we have replied to
- else:
- # Read the file into a list and remove any empty values
- with open("posts_replied_to.txt", "r") as f:
- posts_replied_to = f.read()
- posts_replied_to = posts_replied_to.split("\n")
- posts_replied_to = filter(None, posts_replied_to)
- # Get the top 5 values from our subreddit
- subreddit = r.get_subreddit('pcmasterrace')
- for submission in subreddit.get_hot(limit=10):
- # If we haven't replied to this post before
- if submission.id not in posts_replied_to:
- flair_search(flair="flair:Battlestation",sreddit="pcmasterrace",sort_method="new",search_limit=10)
- flair_search(flair="flair:Build",sreddit="pcmasterrace",sort_method="new",search_limit=10)
- if re.search(likedPosts, submission.title, re.IGNORECASE):
- submission.upvote()
- print("Bot upvoting : {}").format(submission.title)
- posts_replied_to.append(submission.id)
- elif re.search("pc's suck", submission.title, re.IGNORECASE):
- submission.downvote()
- print("Bot Downvoting: {}").format(submission.title)
- post_replied_to.append(submission.id)
- # Write our updated list back to the file
- with open("posts_replied_to.txt", "w") as f:
- for post_id in posts_replied_to:
- f.write(post_id + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement