Example #1
0
def handle(req):
    """handle a request to the function
    Args:
        req (str): request body
    """
    posts = [post for post in get_reddit_posts() if not post['media']]
    return generate_html(posts)
Example #2
0
def handle(req):
    """handle a request to the function
    Args:
        req (str): request body
    """
    posts = get_reddit_posts()
    image_posts = [post for post in posts if post.get('url').endswith(('jpg', 'png', 'gif'))]
    txt = '<br/><ln/>'.join(f"<h3>{post.get('title')}</h3><br><img src={post.get('url')}>" for post in image_posts)
    return txt
Example #3
0
def do_email(source, dest, jobs):
    p = reddit.get_reddit_posts(jobs)
    email = "welcome to your reddit daily digest"
    for sub in p:
        email += "<h4>%s</h4>" % sub['name']
        email += "<br>".join([
            "%d -- %s -- <a href=\"%s\">link</a>" %
            (post['score'], post['title'], post['url'])
            for post in sub['posts']
        ])
    emailreminder.send_email('reddit digest', email, dest, source)
Example #4
0
 def __init__(self, sub, limit):
     self.posts = reddit.get_reddit_posts(sub, limit)
     self.index = 0
Example #5
0
def write_and_update_posts(recent_posts_data, existing_posts_data):

    posts_to_write = []
    posts_to_update = []

    for recent_post in recent_posts_data:
        existing_post = find_post_in_list(recent_post, existing_posts_data)

        if existing_post == None:
            posts_to_write.append(recent_post)

        elif existing_post['source_score'] != recent_post['source_score']:
            posts_to_update.append(recent_post)

    update_ids = [post['id'] for post in posts_to_update]

    print('Writing ' + str(len(posts_to_write)) + ' new posts...')
    print('Updating ' + str(len(posts_to_update)) + ' existing posts...')

    insert_posts(posts_to_write)
    delete_posts_by_source_id(update_ids)
    insert_posts(posts_to_update)


recent_posts_data = get_reddit_posts(REDDIT_CONFIG['test_subreddits'], 500)
recent_ids = [post['id'] for post in recent_posts_data]
existing_posts_data = get_posts_by_source_id(recent_ids)

write_and_update_posts(recent_posts_data, existing_posts_data)
Example #6
0
from reddit import get_reddit_posts
from api import get_post_ids, write_and_update_posts
from config import *
import logging
from logs.config import logger

logger.info('Setup logger')
logger = logging.getLogger('Rentiment.' + __name__)

logger.info('Get posts from reddit...')
posts_data_l = get_reddit_posts(REDDIT_CONFIG['large_crypto_subs'], 500)
posts_data_s = get_reddit_posts(REDDIT_CONFIG['small_crypto_subs'], 100)

logger.info('Insert posts into mongo...')
existing_ids = get_post_ids()
write_and_update_posts(posts_data_l, existing_ids)
write_and_update_posts(posts_data_s, existing_ids)