コード例 #1
0
ファイル: public_users.py プロジェクト: TomDunn/RedditGraph
def update(session, user, praw_post, score):
    post = Post.get_or_create(session, praw_post.id)
    post.update_from_praw(praw_post)
    post.author_id = user.id
    Util.update_subreddit(Subreddit, post, session, praw_post.subreddit.display_name)
    vote = Vote.get_or_create(session, user, post, score)
    vote.vote = score

    session.add(vote)
    session.add(post)
コード例 #2
0
ファイル: get_posts.py プロジェクト: TomDunn/RedditGraph
def main(notify):
    session = Session()
    gen = r.get_subreddit("all").get_top(limit=3000)

    start = session.query(Post).count()
    notify("Getting posts, initial count: %d" % start)
    count = 0

    for post in gen:
        count += 1

        p = Post.get_or_create(session, post.id)
        p.update_from_praw(post)

        author_name = Util.patch_author(post.author)
        Util.update_user(User, p, session, author_name)
        Util.update_subreddit(Subreddit, p, session, post.subreddit.display_name)

        session.add(p)
        session.commit()

    diff = session.query(Post).count() - start
    notify("Added %d posts" % diff)