Ejemplo n.º 1
0
def get_tw_user(user_id, brand_name):
    dic = TWUser.collection().find_one({"u_id": str(user_id), "brand_name": brand_name})
    tw_user = TWUser.unserialize(dic) if dic is not None else None
    if tw_user is not None:
        brand_dic = BrandMapping.collection().find_one({"uid": user_id, "brand_name": brand_name})
        brand = BrandMapping.unserialize(brand_dic) if brand_dic is not None else None
    return tw_user, brand.twitter["access_token"]
Ejemplo n.º 2
0
def save_tw_user(user_id, brand_name, key, secret):
    """
    Add twitter account to the unifide user and spawn thread to pull recent tweewts from home timeline
    """
    api, token_key, token_secret = get_api(key, secret)
    twUser_obj = TWUser()
    twUser_obj.u_id = user_id
    twUser_obj.tw_id = api.me().id_str
    twUser_obj.brand_name = brand_name
    twUser_obj.username = api.me().screen_name

    TWUser.collection().update({"u_id": user_id, "brand_name": brand_name}, twUser_obj.serialize())
    saved_tw_user_obj = TWUser.unserialize(TWUser.collection().find_one({"u_id": user_id, "brand_name": brand_name}))

    update_brand_mapping(user_id, brand_name, "twitter", api.me().id_str, {"key": key, "secret": secret})

    t = Thread(target=save_tweets, args=(user_id, saved_tw_user_obj.tw_id, brand_name))
    t.setDaemon(False)
    t.start()

    return saved_tw_user_obj
Ejemplo n.º 3
0
def get_tw_user_oauth(user_id, brand_name):
    dic = TWUser.collection().find_one({"u_id": user_id, "brand_name": brand_name})
    return TWUser.unserialize(dic) if dic is not None else None