def __init__(self, subreddits, limit=100, deal_threshold=50, upvote_threshold=70): # Maximum no. of submissions to parse for each subreddit self.limit = limit # Threshold used to filter out lower deals self.deal_threshold = deal_threshold # (% off) # Threshold used to filter out less upvoted deals self.upvote_threshold = upvote_threshold # (% ratio between upvotes and downvotes) # Ensure each subreddit is unique self.subreddits = acquire_unique_subreddits(subreddits) # Acquire login information from text file. login_info = Utils.get_login_info() # Acquire submissions from subreddit self.reddit = praw.Reddit(client_id=login_info['client_id'], client_secret=login_info['client_secret'], user_agent=login_info['user_agent'], redirect_uri="http://localhost:8080", username=login_info['username'], password=login_info['password']) # Create parser for each subreddit self.reddit_parsers = [] for subreddit in self.subreddits: self.reddit_parsers.append(RedditParser.RedditParser(subreddit, self.limit, self.deal_threshold, self.upvote_threshold, self.reddit)) # Create mySQL database to hold data self.database = Database.Database()
def avg_post(numPosts): avg = 0 topcom = RedditParser.Parse_Subreddit("all", order=RedditParser.Get_Top_All) for i in range(numPosts): temp = topcom.next() avg += temp[2] #print(temp[2]) return (avg / numPosts)
def top_n_posts_spec(numPosts, r1, spec): #create a generator for the top reddit posts topCom = RedditParser.Parse_Subreddit( spec, order=RedditParser.Get_Top_All) #use .next() to get other elem #iter = 0 #check on the outer while loop count = 0 #number of posts that we have accepted # r1Iter = 0 #move through the r1 array posts = [] for temp in topCom: if (temp[2] > r1): posts.append(temp) return posts
def Save_Random_User_Names(file_name): name_set = set() try: with open(file_name, "r") as f: for line in f: name_set.add(line.rstrip()) except: pass with open(file_name, "a+") as f: k = len(name_set) for user in RedditParser.Random_User_Stream(users=name_set): f.write(user + "\n") k += 1 if k % 100 == 0: print k
def top_n_posts(numPosts, r1): #create a generator for the top reddit posts topCom = RedditParser.Parse_Subreddit( "all", order=RedditParser.Get_Top_All) #use .next() to get other elem #iter = 0 #check on the outer while loop count = 0 #number of posts that we have accepted # r1Iter = 0 #move through the r1 array posts = [] while (count < numPosts): temp = topCom.next() if (temp[2] > r1): posts.append(temp) count += 1 # iter += 1 return posts
def Save_Reddit_User_Names(file_name, subreddit, number): name_set = set() try: with open(file_name, "r") as f: for line in f: name_set.add(line.rstrip()) except: pass with open(file_name, "a+") as f: k = 0 for user in RedditParser.All_Users(subreddit, users=name_set): f.write(user + "\n") k += 1 if k % 100 == 0: print k if k == number: break
def __init__(self): self.twitter_feed = TwitterParser.TwitterParser() self.reddit_feed = RedditParser.RedditParser() self.include_reddit = True self.include_twitter = True
def renew_reddit(self): self.reddit_feed = RedditParser.RedditParser()
import RedditParser if __name__ == "__main__": #r = RedditParser.praw.Reddit(RedditParser.USER_STR) #print r.get_submission(submission_id='20gewk') for comment in RedditParser.All_User_Comments("_vargas_"): print comment #for comment in RedditParser.Parse_Subreddit("math"): #print comment