Exemplo n.º 1
0
def post_links():
    session = Session()
    data = json.loads(request.data)

    for link in data['links']:
        post = Post.get_or_create(session, link['reddit_id'])
        subreddit = Subreddit.get_or_create(session, link['sub_name'])
        user = User.get_or_create(session, link['authorname'])

        post.subreddit_id   = subreddit.id
        post.author_id      = user.id

        post.domain = link['domain']
        post.title  = link['title']
        post.url    = link['url']
        post.score  = link['score']
        post.downs  = link['downs']
        post.ups    = link['ups']

        post.is_self = link['is_self']
        post.over_18 = link['over_18']
        post.thumbnail = link['thumbnail']
        post.created = float(link['created'])
        post.scraped_time = Util.now()

        session.add(post)

    session.commit()
    session.close()
    return jsonify({'received':True})
Exemplo n.º 2
0
def main(notify):
    session = Session()
    gen = r.get_popular_subreddits(limit=30000)

    count = session.query(Subreddit).count()
    notify("Getting subs, initial count: %d" % count)

    for praw_subreddit in gen:
        count += 1

        subreddit = Subreddit.get_or_create(session, praw_subreddit.display_name)
        subreddit.update_from_praw(praw_subreddit)

        session.add(subreddit)

    session.commit()
    notify("Now have %d" % count)