Esempio n. 1
0
def store_user(user, db=1):
    if user is None:
        return
    document = Users.query.filter(Users.uid == user['uid']).first()
    if document:
        document.followers_count = user['followers_count']
        document.friends_count = user['friends_count']
        db_session.add(document)
        db_session.commit()
    else:
        user = Users(**user)
        db_session.add(user)
        db_session.commit()
Esempio n. 2
0
def store_status(status, followers_count=0, db=1):  # 0 mysql 1 psql 2 mongo
    if status is None:
        return
    if status.get('deleted', 0):
        return
    document = Statuses.query.filter(Statuses.wid == status['wid']).first()
    if document:
        document.reposts_count = status['reposts_count']
        document.comments_count = status['comments_count']
        db_session.add(document)
        db_session.commit()
    else:
        if status.get('retweeted_status_id', 0):
            retweeted_status = Statuses.query.filter(Statuses.wid == status['retweeted_status_id']).first()
            if retweeted_status and followers_count >= 10000:
                retweeted_status.counter += 1
                db_session.add(retweeted_status)
        status = Statuses(**status)
        db_session.add(status)
        db_session.commit()