Exemplo 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()
Exemplo 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()
Exemplo n.º 3
0
def update_followers_count(uid):
    WeiboAccounts.query.filter(WeiboAccounts.uid == uid).update(
        {WeiboAccounts.friends_count: WeiboAccounts.friends_count + 1})
    db_session.commit()
Exemplo n.º 4
0
def store_friendships(uid, target_id):
    Users.query.filter(Users.uid == target_id).update(
        {Users.follower: uid})
    db_session.commit()
Exemplo n.º 5
0
def update_access_token(uid, access_token, expires_in):
    WeiboAccounts.query.filter(WeiboAccounts.uid == uid).update(
        {WeiboAccounts.access_token: access_token, WeiboAccounts.expires_in: expires_in})
    db_session.commit()