當前位置: 首頁>>代碼示例>>Python>>正文


Python OAuth2Token.get方法代碼示例

本文整理匯總了Python中past.model.user.OAuth2Token.get方法的典型用法代碼示例。如果您正苦於以下問題:Python OAuth2Token.get方法的具體用法?Python OAuth2Token.get怎麽用?Python OAuth2Token.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在past.model.user.OAuth2Token的用法示例。


在下文中一共展示了OAuth2Token.get方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_client

# 需要導入模塊: from past.model.user import OAuth2Token [as 別名]
# 或者: from past.model.user.OAuth2Token import get [as 別名]
    def get_client(cls, user_id):
        alias = UserAlias.get_by_user_and_type(user_id, config.OPENID_TYPE_DICT[config.OPENID_DOUBAN])
        if not alias:
            return None

        token = OAuth2Token.get(alias.id)
        if not token:
            return None

        return cls(alias.alias, token.access_token, token.refresh_token)
開發者ID:geekontheway,項目名稱:thepast,代碼行數:12,代碼來源:api_client.py

示例2: __init__

# 需要導入模塊: from past.model.user import OAuth2Token [as 別名]
# 或者: from past.model.user.OAuth2Token import get [as 別名]
    def __init__(self, alias, apikey=None, apikey_secret=None, access_token=None, access_token_secret=None):
        ua = UserAlias.get(config.OPENID_TYPE_DICT[config.OPENID_TWITTER], alias)
        self.apikey = apikey if apikey is not None else config.APIKEY_DICT[config.OPENID_TWITTER].get("key")
        self.apikey_secret = apikey_secret if apikey_secret is not None else config.APIKEY_DICT[config.OPENID_TWITTER].get("secret")
        
        token = OAuth2Token.get(ua.id)
        self.access_token = access_token if access_token is not None else token.access_token
        self.access_token_secret = access_token_secret if access_token_secret is not None else token.refresh_token

        self.auth = tweepy.OAuthHandler(self.apikey, self.apikey_secret)        
        self.auth.set_access_token(self.access_token, self.access_token_secret)
開發者ID:Ailocodjam,項目名稱:thepast,代碼行數:13,代碼來源:api_client.py

示例3: sync

# 需要導入模塊: from past.model.user import OAuth2Token [as 別名]
# 或者: from past.model.user.OAuth2Token import get [as 別名]
def sync(cates):
    cates = cates.split("|")
    if not (cates and isinstance(cates, list)):
        return "no cates"

    cates = filter(lambda x: x in [str(y) for y in config.CATE_LIST], cates)
    if not cates:
        abort(400, "not support such cates")

    provider = category2provider(int(cates[0]))
    redir = "/connect/%s" % provider

    if not g.user:
        print '--- no g.user...'
        return redirect(redir)

    if request.form.get("remove"):
        for c in cates:
            r = SyncTask.gets_by_user_and_cate(g.user, str(c))
            for x in r:
                x.remove()
        return json_encode({'ok':'true'})

    uas = UserAlias.gets_by_user_id(g.user.id)
    r = filter(lambda x: x.type == config.OPENID_TYPE_DICT[provider], uas)
    user_alias = r and r[0]
    
    if not user_alias:
        print '--- no user_alias...'
        return json_encode({'ok':'false', 'redir':redir})

    token = OAuth2Token.get(user_alias.id)   
    
    if not token:
        print '--- no token...'
        return json_encode({'ok':'false', 'redir':redir})

    for c in cates:
        SyncTask.add(c, g.user.id)
    
    return json_encode({'ok':'true'})
開發者ID:icycore,項目名稱:thepast,代碼行數:43,代碼來源:views.py

示例4: sync

# 需要導入模塊: from past.model.user import OAuth2Token [as 別名]
# 或者: from past.model.user.OAuth2Token import get [as 別名]
def sync(t, old=False):
    if not t:
        print 'no such task'
        return 0
    log.info("the sync task is :%s" % t)
    try:
        alias = None
        provider = category2provider(t.category)
        if provider == config.OPENID_DOUBAN:
            alias = UserAlias.get_by_user_and_type(t.user_id, 
                    config.OPENID_TYPE_DICT[config.OPENID_DOUBAN])
        elif provider == config.OPENID_SINA:
            alias = UserAlias.get_by_user_and_type(t.user_id, 
                    config.OPENID_TYPE_DICT[config.OPENID_SINA])
        elif provider == config.OPENID_TWITTER:
            alias = UserAlias.get_by_user_and_type(t.user_id, 
                    config.OPENID_TYPE_DICT[config.OPENID_TWITTER])
        elif provider == config.OPENID_QQ:
            alias = UserAlias.get_by_user_and_type(t.user_id,
                    config.OPENID_TYPE_DICT[config.OPENID_QQ])
        if not alias:
            log.warn("no alias...")
            return 0

        token = OAuth2Token.get(alias.id)
        if not token:
            log.warn("no access token, break...")
            return 0
        
        client = None
        if provider == config.OPENID_DOUBAN:
            client = Douban(alias.alias, token.access_token, token.refresh_token)
        elif provider == config.OPENID_SINA:
            client = SinaWeibo(alias.alias, token.access_token)
        elif provider == config.OPENID_TWITTER:
            client = Twitter(alias.alias)
        elif provider == config.OPENID_QQ:
            client = QQWeibo(alias.alias)
        if not client:
            log.warn("get client fail, break...")
            return 0

        if t.category == config.CATE_DOUBAN_NOTE:
            if old:
                start = Status.get_count_by_cate(t.category, t.user_id)
            else:
                start = 0
            note_list = client.get_notes(start, 50)
            if note_list:
                for x in note_list:
                    Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
                return len(note_list)
        elif t.category == config.CATE_DOUBAN_MINIBLOG:
            if old:
                start = Status.get_count_by_cate(t.category, t.user_id)
            else:
                start = 0
            miniblog_list = client.get_miniblogs(start, 50)
            if miniblog_list:
                for x in miniblog_list:
                    Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
                return len(miniblog_list)
        elif t.category == config.CATE_DOUBAN_STATUS:
            origin_min_id = Status.get_min_origin_id(t.category, t.user_id)
            if old:
                log.info("will get douban status order than %s..." % origin_min_id)
                status_list = client.get_timeline(until_id=origin_min_id)
            else:
                log.info("will get douban status newer than %s..." % origin_min_id)
                status_list = client.get_timeline(since_id=origin_min_id, count=20)
            if status_list:
                log.info("get douban status succ, len is %s" % len(status_list))
                for x in status_list:
                    Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
                
        elif t.category == config.CATE_SINA_STATUS:
            origin_min_id = Status.get_min_origin_id(t.category, t.user_id) #means max_id
            if old:
                log.info("will get sinaweibo order than %s..." % origin_min_id)
                status_list = client.get_timeline(until_id=origin_min_id)
                ## 如果根據max_id拿不到數據,那麽根據page再拿一次
                if len(status_list) <= 1:
                    downloaded_status_count = Status.get_count_by_user(t.user_id)
                    page = downloaded_status_count / 100 + 2
                    status_list = client.get_timeline_by_page(page=page)
            else:
                log.info("will get sinaweibo newer than %s..." % origin_min_id)
                status_list = client.get_timeline(since_id=origin_min_id, count=20)
            if status_list:
                log.info("get sinaweibo succ, len is %s" % len(status_list))
                for x in status_list:
                    Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
                return len(status_list)
        elif t.category == config.CATE_TWITTER_STATUS:
            origin_min_id = Status.get_min_origin_id(t.category, t.user_id)
            if old:
                log.info("will get tweets order than %s..." % origin_min_id)
                status_list = client.get_timeline(max_id=origin_min_id)
            else:
                log.info("will get tweets newer than %s..." % origin_min_id)
#.........這裏部分代碼省略.........
開發者ID:Ailocodjam,項目名稱:thepast,代碼行數:103,代碼來源:jobs.py

示例5: sync

# 需要導入模塊: from past.model.user import OAuth2Token [as 別名]
# 或者: from past.model.user.OAuth2Token import get [as 別名]
def sync(t, old=False):
    alias = None
    provider = category2provider(t.category)
    if provider == config.OPENID_DOUBAN:
        alias = UserAlias.get_by_user_and_type(t.user_id, 
                config.OPENID_TYPE_DICT[config.OPENID_DOUBAN])
    elif provider == config.OPENID_SINA:
        alias = UserAlias.get_by_user_and_type(t.user_id, 
                config.OPENID_TYPE_DICT[config.OPENID_SINA])
    elif provider == config.OPENID_TWITTER:
        alias = UserAlias.get_by_user_and_type(t.user_id, 
                config.OPENID_TYPE_DICT[config.OPENID_TWITTER])
    elif provider == config.OPENID_QQ:
        alias = UserAlias.get_by_user_and_type(t.user_id,
                config.OPENID_TYPE_DICT[config.OPENID_QQ])
    if not alias:
        log.warn("no alias...")
        return 0

    token = OAuth2Token.get(alias.id)
    if not token:
        log.warn("no access token, break...")
        return 0
    
    client = None
    if provider == config.OPENID_DOUBAN:
        client = Douban(alias.alias, token.access_token, token.refresh_token)
    elif provider == config.OPENID_SINA:
        client = SinaWeibo(alias.alias, token.access_token)
    elif provider == config.OPENID_TWITTER:
        client = Twitter(alias.alias)
    elif provider == config.OPENID_QQ:
        client = QQWeibo(alias.alias)
    if not client:
        log.warn("get client fail, break...")
        return 0

    if t.category == config.CATE_DOUBAN_NOTE:
        if old:
            start = Status.get_count_by_cate(t.category, t.user_id)
        else:
            start = 0
        note_list = client.get_notes(start, 50)
        if note_list:
            for x in note_list:
                Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
            return len(note_list)
    elif t.category == config.CATE_DOUBAN_MINIBLOG:
        if old:
            start = Status.get_count_by_cate(t.category, t.user_id)
        else:
            start = 0
        miniblog_list = client.get_miniblogs(start, 50)
        if miniblog_list:
            for x in miniblog_list:
                Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
            return len(miniblog_list)
    elif t.category == config.CATE_DOUBAN_STATUS or t.category == config.CATE_SINA_STATUS:
        if old:
            until_id = Status.get_min_origin_id(t.category, t.user_id) #means max_id
            status_list = client.get_timeline(until_id=until_id)
        else:
            since_id = Status.get_min_origin_id(t.category, t.user_id)
            status_list = client.get_timeline(since_id=since_id)
        if status_list:
            for x in status_list:
                Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
            return len(status_list)
    elif t.category == config.CATE_TWITTER_STATUS:
        if old:
            until_id = Status.get_min_origin_id(t.category, t.user_id) #means max_id
            status_list = client.get_timeline(max_id=until_id)
        else:
            since_id = Status.get_min_origin_id(t.category, t.user_id)
            status_list = client.get_timeline(since_id=since_id)
        if status_list:
            for x in status_list:
                Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
            return len(status_list)
    elif t.category == config.CATE_QQWEIBO_STATUS:
        if old:
            oldest_create_time = Status.get_oldest_create_time(t.category, t.user_id)
            oldest_create_time = datetime2timestamp(oldest_create_time)
            status_list = client.get_old_timeline(oldest_create_time, reqnum=200)
        else:
            status_list = client.get_new_timeline(reqnum=20)
        if status_list:
            for x in status_list:
                Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
            return len(status_list)
    return 0
開發者ID:FANWENBIN,項目名稱:thepast,代碼行數:93,代碼來源:jobs.py

示例6: sync

# 需要導入模塊: from past.model.user import OAuth2Token [as 別名]
# 或者: from past.model.user.OAuth2Token import get [as 別名]
def sync(t, old=False):
    if not t:
        print 'no such task'
        return 0
    log.info("the sync task is :%s" % t)
    try:
        alias = None
        provider = category2provider(t.category)

        alias = UserAlias.get_by_user_and_type(t.user_id,
                config.OPENID_TYPE_DICT[provider])
        if not alias:
            log.warn("no alias...")
            return 0

        token = OAuth2Token.get(alias.id)
        if not token:
            log.warn("no access token, break...")
            return 0
        
        client = None
        if provider == config.OPENID_DOUBAN:
            client = Douban.get_client(alias.user_id)
        elif provider == config.OPENID_SINA:
            client = SinaWeibo.get_client(alias.user_id)
        elif provider == config.OPENID_TWITTER:
            client = TwitterOAuth1.get_client(alias.user_id)
        elif provider == config.OPENID_QQ:
            client = QQWeibo.get_client(alias.user_id)
        elif provider == config.OPENID_RENREN:
            client = Renren.get_client(alias.user_id)
        elif provider == config.OPENID_INSTAGRAM:
            client = Instagram.get_client(alias.user_id)
        if not client:
            log.warn("get client fail, break...")
            return 0

        if t.category == config.CATE_DOUBAN_NOTE:
            if old:
                start = Status.get_count_by_cate(t.category, t.user_id)
            else:
                start = 0
            note_list = client.get_notes(start, 50)
            if note_list:
                for x in note_list:
                    Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
                return len(note_list)
        elif t.category == config.CATE_DOUBAN_MINIBLOG:
            if old:
                start = Status.get_count_by_cate(t.category, t.user_id)
            else:
                start = 0
            miniblog_list = client.get_miniblogs(start, 50)
            if miniblog_list:
                for x in miniblog_list:
                    Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
                return len(miniblog_list)
        elif t.category == config.CATE_DOUBAN_STATUS:
            origin_min_id = Status.get_min_origin_id(t.category, t.user_id)
            if old:
                log.info("will get douban status order than %s..." % origin_min_id)
                status_list = client.get_timeline(until_id=origin_min_id)
            else:
                log.info("will get douban status newer than %s..." % origin_min_id)
                status_list = client.get_timeline(since_id=origin_min_id, count=20)
            if status_list:
                log.info("get douban status succ, len is %s" % len(status_list))
                for x in status_list:
                    Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
                
        elif t.category == config.CATE_SINA_STATUS:
            origin_min_id = Status.get_min_origin_id(t.category, t.user_id) #means the earliest id
            origin_max_id = Status.get_max_origin_id(t.category, t.user_id) #meas the latest id
            if old:
                log.info("will get sinaweibo order than %s..." % origin_min_id)
                status_list = client.get_timeline(until_id=origin_min_id)
                ## 如果根據max_id拿不到數據,那麽根據page再fetch一次或者until_id - 1
                if status_list and len(status_list) < 20 and origin_min_id is not None:
                    log.info("again will get sinaweibo order than %s..." % (int(origin_min_id)-1))
                    status_list = client.get_timeline(until_id=int(origin_min_id)-1)
            else:
                log.info("will get sinaweibo newer than %s..." % origin_max_id)
                status_list = client.get_timeline(since_id=origin_max_id, count=50)
            if status_list:
                log.info("get sinaweibo succ, len is %s" % len(status_list))
                for x in status_list:
                    Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
                return len(status_list)
        elif t.category == config.CATE_TWITTER_STATUS:
            origin_min_id = Status.get_min_origin_id(t.category, t.user_id)
            origin_max_id = Status.get_max_origin_id(t.category, t.user_id)
            if old:
                log.info("will get tweets order than %s..." % origin_min_id)
                status_list = client.get_timeline(max_id=origin_min_id)
            else:
                log.info("will get tweets newer than %s..." % origin_max_id)
                status_list = client.get_timeline(since_id=origin_max_id, count=50)
            if status_list:
                log.info("get tweets succ, len is %s" % len(status_list))
                for x in status_list:
#.........這裏部分代碼省略.........
開發者ID:EdwinHi,項目名稱:thepast,代碼行數:103,代碼來源:jobs.py


注:本文中的past.model.user.OAuth2Token.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。