コード例 #1
0
ファイル: views.py プロジェクト: zhangdjxx/thepast
def post_status(user, provider=None, msg=""):
    if msg and isinstance(msg, unicode):                                           
        msg = msg.encode("utf8") 
    if not provider or provider == config.OPENID_TYPE_DICT[config.OPENID_DOUBAN]:
        print "++++++++++post douban status"
        client = Douban.get_client(user.id)
        if client:
            if not msg:
                msg = "#thepast.me# 你好,旧时光| 我在用thepast, 广播备份,往事提醒,你也来试试吧 >> http://thepast.me "
            client.post_status(msg)

    if not provider or provider == config.OPENID_TYPE_DICT[config.OPENID_SINA]:
        print "++++++++++post sina status"
        client = SinaWeibo.get_client(user.id)
        if client:
            if not msg:
                msg = "#thepast.me# 你好,旧时光| 我在用thepast, 微博备份,往事提醒,你也来试试吧 >> http://thepast.me "
            client.post_status(msg)

    if not provider or provider == config.OPENID_TYPE_DICT[config.OPENID_TWITTER]:
        print "++++++++post twitter status"
        client = TwitterOAuth1.get_client(user.id)
        if client:
            if not msg:
                msg = "#thepast.me# 你好,旧时光| 我在用thepast, twitter备份,往事提醒,你也来试试吧 >> http://thepast.me "
            client.post_status(msg)

    if not provider or provider == config.OPENID_TYPE_DICT[config.OPENID_QQ]:
        print "++++++++post qq weibo status"
        client = QQWeibo.get_client(user.id)
        if client:
            if not msg:
                msg = "#thepast.me# 你好,旧时光| 我在用thepast, 微博备份,往事提醒,你也来试试吧 >> http://thepast.me "
            client.post_status(msg)
コード例 #2
0
ファイル: views.py プロジェクト: icycore/thepast
def post_status(user, provider=None, msg=""):
    if msg and isinstance(msg, unicode):                                           
        msg = msg.encode("utf8") 
    if not provider or provider == config.OPENID_TYPE_DICT[config.OPENID_DOUBAN]:
        print "++++++++++post douban status"
        client = Douban.get_client(user.id)
        if client:
            if not msg:
                msg = "#thepast.me# 你好,旧时光| 我在用thepast, 广播备份,往事提醒,你也来试试吧 >> http://thepast.me "
            client.post_status(msg)

    if not provider or provider == config.OPENID_TYPE_DICT[config.OPENID_SINA]:
        print "++++++++++post sina status"
        client = SinaWeibo.get_client(user.id)
        if client:
            if not msg:
                msg = "#thepast.me# 你好,旧时光| 我在用thepast, 微博备份,往事提醒,你也来试试吧 >> http://thepast.me "
            client.post_status(msg)

    if not provider or provider == config.OPENID_TYPE_DICT[config.OPENID_TWITTER]:
        print "++++++++post twitter status"
        client = TwitterOAuth1.get_client(user.id)
        if client:
            if not msg:
                msg = "#thepast.me# 你好,旧时光| 我在用thepast, twitter备份,往事提醒,你也来试试吧 >> http://thepast.me "
            client.post_status(msg)

    if not provider or provider == config.OPENID_TYPE_DICT[config.OPENID_QQ]:
        print "++++++++post qq weibo status"
        client = QQWeibo.get_client(user.id)
        if client:
            if not msg:
                msg = "#thepast.me# 你好,旧时光| 我在用thepast, 微博备份,往事提醒,你也来试试吧 >> http://thepast.me "
            client.post_status(msg)
コード例 #3
0
def connect(provider):
    if provider == "renren":
        return "人人的api因为备案问题尚未审核通过,请先绑定其他平台吧,比如豆瓣:)"
    #return "thepast.me 正在升级硬件,暂时不提供登录、注册功能,请谅解,有问题请邮件到 [email protected]"

    client = None
    if provider == config.OPENID_DOUBAN:
        client = Douban()
    elif provider == config.OPENID_SINA:
        client = SinaWeibo()
    elif provider == config.OPENID_TWITTER:
        client = TwitterOAuth1()
    elif provider == config.OPENID_QQ:
        client = QQWeibo()
    elif provider == config.OPENID_RENREN:
        client = Renren()
    elif provider == config.OPENID_INSTAGRAM:
        client = Instagram()
    if not client:
        abort(400, "不支持该第三方登录")

    try:
        login_uri = client.login()
    except OAuthError, e:
        log.warning(e)
        abort(400, "抱歉,跳转到第三方失败,请重新尝试一下:)")
コード例 #4
0
ファイル: view.py プロジェクト: zhukaixy/thepast
def connect(provider):
    if provider == "renren":
        return "我已经实在受不了人人,被人人的管理员快搞死了,怎么修改都不通过,唉...  有兴趣可以看看这边豆瓣网友的帖子:http://www.douban.com/note/250372684/"
    #return "thepast.me 正在升级硬件,暂时不提供登录、注册功能,请谅解,有问题请邮件到 [email protected]"

    client = None
    if provider == config.OPENID_DOUBAN:
        client = Douban()
    elif provider == config.OPENID_SINA:
        client = SinaWeibo()
    elif provider == config.OPENID_TWITTER:
        client = TwitterOAuth1()
    elif provider == config.OPENID_QQ:
        client = QQWeibo()
    elif provider == config.OPENID_RENREN:
        client = Renren()
    elif provider == config.OPENID_INSTAGRAM:
        client = Instagram()
    if not client:
        abort(400, "不支持该第三方登录")

    try:
        login_uri = client.login()
    except OAuthError, e:
        log.warning(e)
        abort(400, "抱歉,跳转到第三方失败,请重新尝试一下:)")
コード例 #5
0
def connect_callback(provider):
    code = request.args.get("code")

    client = None
    user = None

    openid_type = config.OPENID_TYPE_DICT.get(provider)
    if not openid_type:
        abort(404, "not support such provider")

    if provider in [
            config.OPENID_DOUBAN,
            config.OPENID_SINA,
            config.OPENID_RENREN,
            config.OPENID_INSTAGRAM,
    ]:
        if provider == config.OPENID_DOUBAN:
            client = Douban()
        elif provider == config.OPENID_SINA:
            client = SinaWeibo()
        elif provider == config.OPENID_RENREN:
            client = Renren()
        elif provider == config.OPENID_INSTAGRAM:
            client = Instagram()

        ## oauth2方式授权处理
        try:
            token_dict = client.get_access_token(code)
            print "---token_dict", token_dict
        except OAuthError, e:
            log.warning(e)
            abort(400, u"从第三方获取access_token失败了,请重新尝试一下,抱歉:)")

        if not (token_dict and token_dict.get("access_token")):
            abort(400, "no_access_token")
        try:
            access_token = token_dict.get("access_token", "")
            refresh_token = token_dict.get("refresh_token", "")
            #the last is instagram case:)
            uid = token_dict.get("uid") or token_dict.get("user", {}).get("uid") \
                    or token_dict.get("user", {}).get("id")
            client.set_token(access_token, refresh_token)
            user_info = client.get_user_info(uid)
            print "---user_info", user_info, user_info.data
        except OAuthError, e:
            log.warning(e)
            abort(400, e.msg)
コード例 #6
0
ファイル: view.py プロジェクト: loosky/thepast
def connect(provider):
    if provider == "renren":
        return "人人的api因为备案问题尚未审核通过,请先绑定其他平台吧,比如豆瓣:)"
    #return "thepast.me 正在升级硬件,暂时不提供登录、注册功能,请谅解,有问题请邮件到 [email protected]"

    client = None
    if provider == config.OPENID_DOUBAN:
        client = Douban()
    elif provider == config.OPENID_SINA:
        client = SinaWeibo()
    elif provider == config.OPENID_TWITTER:
        client = TwitterOAuth1()
    elif provider == config.OPENID_QQ:
        client = QQWeibo()
    elif provider == config.OPENID_RENREN:
        client = Renren()
    elif provider == config.OPENID_INSTAGRAM:
        client = Instagram()
    if not client:
        abort(400, "不支持该第三方登录")

    try:
        login_uri = client.login()
    except OAuthError, e:
        log.warning(e)
        abort(400, "抱歉,跳转到第三方失败,请重新尝试一下:)")
コード例 #7
0
ファイル: view.py プロジェクト: EdwinHi/thepast
def connect(provider):
    if provider == "renren":
        return "我已经实在受不了人人,被人人的管理员快搞死了,怎么修改都不通过,唉...  有兴趣可以看看这边豆瓣网友的帖子:http://www.douban.com/note/250372684/"
    #return "thepast.me 正在升级硬件,暂时不提供登录、注册功能,请谅解,有问题请邮件到 [email protected]"

    client = None
    if provider == config.OPENID_DOUBAN:
        client = Douban()
    elif provider == config.OPENID_SINA:
        client = SinaWeibo()
    elif provider == config.OPENID_TWITTER:
        client = TwitterOAuth1()
    elif provider == config.OPENID_QQ:
        client = QQWeibo()
    elif provider == config.OPENID_RENREN:
        client = Renren()
    elif provider == config.OPENID_INSTAGRAM:
        client = Instagram()
    if not client:
        abort(400, "不支持该第三方登录")

    try:
        login_uri = client.login()
    except OAuthError, e:
        log.warning(e)
        abort(400, "抱歉,跳转到第三方失败,请重新尝试一下:)")
コード例 #8
0
ファイル: view.py プロジェクト: loosky/thepast
def connect_callback(provider):
    code = request.args.get("code")

    client = None
    user = None

    openid_type = config.OPENID_TYPE_DICT.get(provider)
    if not openid_type:
        abort(404, "not support such provider")

    if provider in [config.OPENID_DOUBAN, config.OPENID_SINA, config.OPENID_RENREN,
            config.OPENID_INSTAGRAM,]:
        if provider == config.OPENID_DOUBAN:
            client = Douban()
        elif provider == config.OPENID_SINA:
            client = SinaWeibo()
        elif provider == config.OPENID_RENREN:
            client = Renren()
        elif provider == config.OPENID_INSTAGRAM:
            client = Instagram()

        ## oauth2方式授权处理
        try:
            token_dict = client.get_access_token(code)
            print "---token_dict", token_dict
        except OAuthError, e:
            log.warning(e)
            abort(400, u"从第三方获取access_token失败了,请重新尝试一下,抱歉:)")

        if not (token_dict and token_dict.get("access_token")):
            abort(400, "no_access_token")
        try:
            access_token = token_dict.get("access_token", "") 
            refresh_token = token_dict.get("refresh_token", "") 
            #the last is instagram case:)
            uid = token_dict.get("uid") or token_dict.get("user", {}).get("uid") \
                    or token_dict.get("user", {}).get("id")
            client.set_token(access_token, refresh_token)
            user_info = client.get_user_info(uid)
            print "---user_info", user_info
        except OAuthError, e:
            log.warning(e)
            abort(400, e.msg)
コード例 #9
0
ファイル: jobs.py プロジェクト: zhukaixy/thepast
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:
                    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)
                log.info("will get qqweibo order than %s" % oldest_create_time)
                if oldest_create_time is not None:
                    oldest_create_time = datetime2timestamp(oldest_create_time)
                status_list = client.get_old_timeline(oldest_create_time, reqnum=200)
            else:
                log.info("will get qqweibo new timeline")
                status_list = client.get_new_timeline(reqnum=20)
            if status_list:
                log.info("get qqweibo succ, result length 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_RENREN_STATUS:
            if old:
                count = 100
                total_count = Status.get_count_by_cate(t.category, t.user_id)
                page = int(total_count / count) + 1
                log.info("will get older renren status, page=%s, count=%s" %(page, count))
                status_list = client.get_timeline(page, count)
            else:
                count = 20
                page = 1
                log.info("will get newest renren status, page=%s, count=%s" %(page, count))
                status_list = client.get_timeline(page, count)
            if status_list:
                log.info("get renren status succ, result length 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_RENREN_BLOG:
            if old:
                count = 50
                total_count = Status.get_count_by_cate(t.category, t.user_id)
                page = int(total_count / count) + 1
                log.info("will get older renren blog, page=%s, count=%s" %(page, count))
                blogs = client.get_blogs(page, count)
            else:
                count = 20
                page = 1
                log.info("will get newest renren blog, page=%s, count=%s" %(page, count))
                blogs = client.get_blogs(page, count)
            if blogs:
                uid = blogs.get("uid")
                blog_ids = filter(None, [v.get("id") for v in blogs.get("blogs", [])])
                log.info("get renren blog ids succ, result length is:%s" % len(blog_ids))
                for blog_id in blog_ids:
                    blog = client.get_blog(blog_id, uid)
                    if blog:
                        Status.add_from_obj(t.user_id, blog, json_encode(blog.get_data()))
                return len(blog_ids)
        elif t.category == config.CATE_RENREN_ALBUM:
            status_list = client.get_albums()
            if status_list:
                log.info("get renren album succ, result length 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_RENREN_PHOTO:
            albums_ids = Status.get_ids(user_id=t.user_id, limit=1000, cate=config.CATE_RENREN_ALBUM)
            albums = Status.gets(albums_ids)
            if not albums:
                return 0
            for x in albums:
                d = x.get_data()
                if not d:
                    continue
                aid = d.get_origin_id()
                size = int(d.get_size())
                count = 50
                for i in xrange(1, size/count + 2):
                    status_list = client.get_photos(aid, i, count)
                    if status_list:
                        log.info("get renren photo of album %s succ, result length is:%s" \
                                % (aid, 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_INSTAGRAM_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) #means the latest id
            if old:
                log.info("will get instagram earlier than %s..." % origin_min_id)
                status_list = client.get_timeline(max_id=origin_min_id)
            else:
                log.info("will get instagram later than %s..." % origin_max_id)
                status_list = client.get_timeline(min_id=origin_max_id, count=50)
            if status_list:
                log.info("get instagram 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)
    except Exception, e:
        print "---sync_exception_catched:", e