当前位置: 首页>>代码示例>>Python>>正文


Python OAuthRequest.to_url方法代码示例

本文整理汇总了Python中oauth.OAuthRequest.to_url方法的典型用法代码示例。如果您正苦于以下问题:Python OAuthRequest.to_url方法的具体用法?Python OAuthRequest.to_url怎么用?Python OAuthRequest.to_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oauth.OAuthRequest的用法示例。


在下文中一共展示了OAuthRequest.to_url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: netflix_movie_from_title

# 需要导入模块: from oauth import OAuthRequest [as 别名]
# 或者: from oauth.OAuthRequest import to_url [as 别名]
def netflix_movie_from_title(cur_movie, only_id=False):
    movie = Movies()
    if cur_movie and cur_movie.Title and cur_movie.Year:
        try:
            # Query netflix search API with OAuth
            consumer = {
                "oauth_token": settings.API_KEYS["NETFLIX"],
                "oauth_token_secret": settings.API_KEYS["NETFLIX_SECRET"],
            }
            params = {"term": cur_movie.Title, "start_index": 0, "max_results": 5}
            request = OAuthRequest("http://api-public.netflix.com/catalog/titles", "GET", params)
            request.sign_request(OAuthSignatureMethod_HMAC_SHA1, consumer)
            url = request.to_url(include_oauth=True)
            req = urllib2.Request(url)
            res = urllib2.urlopen(req)
            if res.getcode() == 200:
                # Parse xml response
                dom = parseString(res.read())
                for node in dom.getElementsByTagName("catalog_title"):
                    # If year is the same
                    if (
                        node.getElementsByTagName("release_year")
                        and node.getElementsByTagName("release_year")[0]
                        and abs(cur_movie.Year - int(node.getElementsByTagName("release_year")[0].childNodes[0].data))
                        < 1
                    ):
                        if node.getElementsByTagName("id") and node.getElementsByTagName("id")[0]:
                            if only_id:
                                return {
                                    "id": netflix_id_from_input(
                                        str(node.getElementsByTagName("id")[0].childNodes[0].data)
                                    )
                                }
                            else:
                                return movie_from_netflix_input(node.getElementsByTagName("id")[0].childNodes[0].data)
                return {"error_msg": "Invalid"}
            else:
                return {"error_msg": "Invalid"}
        except Exception:
            return {"error_msg": "Netflix API failed, please try again"}
    else:
        return {"error_msg": "No title to search from."}
开发者ID:ahampt,项目名称:Pref,代码行数:44,代码来源:id_tools.py

示例2: get_netflix_dom

# 需要导入模块: from oauth import OAuthRequest [as 别名]
# 或者: from oauth.OAuthRequest import to_url [as 别名]
def get_netflix_dom(netflix_id, href=None):
    try:
        # Query netflix API using OAuth
        consumer = {
            "oauth_token": settings.API_KEYS["NETFLIX"],
            "oauth_token_secret": settings.API_KEYS["NETFLIX_SECRET"],
        }
        request = None
        if href:
            request = OAuthRequest(href)
        else:
            request = OAuthRequest("http://api-public.netflix.com/catalog/titles/movies/" + netflix_id)
        request.sign_request(OAuthSignatureMethod_HMAC_SHA1, consumer)
        url = request.to_url(include_oauth=True)
        req = urllib2.Request(url)
        res = urllib2.urlopen(req)
        if res.getcode() == 200:
            # Parse xml response
            return parseString(res.read())
        else:
            return {"Response": False}
    except Exception:
        return {"Response": False}
开发者ID:ahampt,项目名称:Pref,代码行数:25,代码来源:id_tools.py


注:本文中的oauth.OAuthRequest.to_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。