def search_submissions(user_specs: list, notification_on=False): """ Searches through /r/LaptopDeals for submissions that match the given specs The keys in the defaultdict, links, will be the submission title while the values will be a list containing the permalink as the first item and the direct url to purchase the laptop as the second item new_link will represent whehter the submission is new when notifactions are turned on, otherwise new_link will be set to True """ print("\nFinding submissions...") while True: try: links = defaultdict(list) submission_stream = reddit.subreddit(SUBREDDIT).hot( limit=150) if notification_on == False else reddit.subreddit( SUBREDDIT).new(limit=150) start_time = time.time() for submission in submission_stream: submission_title = submission.title.translate(NONE_BMP_CHAR) good_link = _match_specs(user_specs, submission, submission_title) new_link = submission.created_utc > start_time if notification_on == True else True if good_link == True and new_link == True: submission_link = REDDIT_FORMAT + submission.permalink links[submission_title] = [submission_link, submission.url] return links except Exception as e: print(e)
async def cursedimages(ctx): sub = reddit.subreddit('cursedimages') post = sub.random() try: em = discord.Embed(title=post.title, url="https://www.reddit.com{0}".format( post.permalink), color=badColors) em.set_image(url=post.url) em.set_footer( text="👌 {0} | 👄 {1}".format(post.score, post.num_comments)) await client.send_message(ctx.message.channel, embed=em) except Exception as e: await client.say("An error has occurred. The error is:\n{0}".format(e))
async def cursedcomments(ctx): sub = reddit.subreddit('cursedcomments') post = sub.random() #the sub variable grabs the subreddit, and then post grabs a random post from that subreddit try: em = discord.Embed(title=post.title, url="https://www.reddit.com{0}".format( post.permalink), color=badColors) em.set_image(url=post.url) em.set_footer( text="👌 {0} | 👄 {1}".format(post.score, post.num_comments)) await client.send_message(ctx.message.channel, embed=em) #creates an embed with the information from the post, with ok hand being upvotes, and lips being comments, since those seemed more cursed to me except Exception as e: await client.say("An error has occurred. The error is:\n{0}".format(e))
import praw import pickle from teams import teamName from config import reddit for team in teamName: submission_ids = [] fh = open(team + "_ids.py", "wb") pickle.dump(submission_ids, fh) fh.close() subreddit = reddit.subreddit(team) for submission in subreddit.submissions(1508284800, 1522454400): submission_ids.append(submission.id) fh = open(team + "_ids.py", 'wb') pickle.dump(submission_ids, fh) fh.close()
from config import reddit import redis import json import time all_ = reddit.subreddit('all') redis_client = redis.Redis(host='redis', port=6379) REDIS_POSTS_QUEUE = 'POSTS_QUEUE' def publish(data): """ Post data to a Redis queue. """ redis_client.lpush(REDIS_POSTS_QUEUE, json.dumps(data)) def read(): """ Read reddit's stream of submissions on r/all. """ count = 0 for post in all_.stream.submissions(): # Let's start with publishing # just the subreddit name if count > 100: break data = {'subreddit': post.subreddit.display_name} publish(data) print(f'Published {count+1} posts.') count += 1 time.sleep(2) # add a bit of delay
''' montrealReddit is a package for Montreal Bot ''' import praw import re import random from config import reddit montreal = reddit.subreddit('montreal') def isURL(s): return not ('.com' in s or '.jpg' in s or '.net' in s or '.ca' in s or '.org' in s or '.io' in s or '.it' in s) def isImage(s): return '.jpg' in s def getData(flair, time='day', image=False): data = [] data_listing = montreal.top(time) for report in data_listing: if report.link_flair_text != flair or isURL(report.url): continue if image and not isImage(report.url): continue data_dict = dict() data_dict['url'] = report.url data_dict['author'] = report.author