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


Python TestOAuthClient.access_resource方法代码示例

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


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

示例1: profileScrape

# 需要导入模块: from test_oauth_client import TestOAuthClient [as 别名]
# 或者: from test_oauth_client.TestOAuthClient import access_resource [as 别名]
def profileScrape():

    global POINTS

    resource_url = "/api/v1/user"

    client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
    start = time.time()
    response = client.access_resource(resource_url, ACCESS_TOKEN)
    mongoclient = MongoClient()
    db = mongoclient.flexkhan


    start = time.time()
    parsed_json = json.loads(response)
    length = len(parsed_json)
    profile = db.profile
    find = profile.find({})
    
    dbCount = profile.find({}).count()-1

    end = time.time()
    if dbCount == 0:
        POINTS = find[0]["points"]

    if parsed_json["points"] == POINTS:
        print "Match"
    else:
        print "No Match"
        result = db.profile.insert_one(parsed_json)
        POINTS = parsed_json["points"]
开发者ID:fjbarrett,项目名称:flexkhan,代码行数:33,代码来源:updateR.py

示例2: get_api_resource

# 需要导入模块: from test_oauth_client import TestOAuthClient [as 别名]
# 或者: from test_oauth_client.TestOAuthClient import access_resource [as 别名]
def get_api_resource():

    global result, ticker

    resource_url = "/api/v1/user/exercises/progress_changes"

    client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
    start = time.time()
    response = client.access_resource(resource_url, ACCESS_TOKEN)
    end = time.time()

    print type(response)
    print "\n"
    parsed_json = json.loads(response)
    print type(parsed_json)
    length = len(parsed_json)
    mclient = MongoClient()
    db = mclient.flexkhan
    progress = db.progress
    # result = db.progress.insert_one(parsed_json[0])
    result = progress.find()
    size = result.count()
    ticker = 0
    while ticker < size:
       date = datetime.strptime(result[ticker]['date'], "%Y-%m-%dT%H:%M:%SZ")
       aware = pytz.timezone('US/Mountain').localize(date)
       utc_dt = aware.astimezone(pytz.utc)
       print utc_dt.strftime("%Y:%m:%d %I:%M:%S")
       ticker += 1

    print "\nTime: %ss\n" % (end - start)
开发者ID:fjbarrett,项目名称:flexkhan,代码行数:33,代码来源:updateR.py

示例3: progressUpdate

# 需要导入模块: from test_oauth_client import TestOAuthClient [as 别名]
# 或者: from test_oauth_client.TestOAuthClient import access_resource [as 别名]
def progressUpdate():

    resource_url = "/api/v1/user/exercises/progress_changes"

    client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
    response = client.access_resource(resource_url, ACCESS_TOKEN)
    mongoclient = MongoClient()
    db = mongoclient.flexkhan

    counter = 0
    while counter == 0:
        start = time.time()
        parsed_json = json.loads(response)
        freshSize = len(parsed_json)
        progress = db.progress
        find = progress.find({})
        currentDBCount = progress.find({}).count()
        
        if currentDBCount != freshSize:
            diff = freshSize - currentDBCount
            diffcounter = diff 
            i = 0
            while i < diffcounter:
                marker = freshSize-diff+i
                print parsed_json[marker]
                print "\n"
                print marker
                result = db.progress.insert_one(parsed_json[marker])
                i += 1
        else:
            print("No diff")
        
        # print "\nTime: %ss\n" % (end - start) 
        counter = 1 
开发者ID:fjbarrett,项目名称:flexkhan,代码行数:36,代码来源:updateR.py

示例4: get_api_resource

# 需要导入模块: from test_oauth_client import TestOAuthClient [as 别名]
# 或者: from test_oauth_client.TestOAuthClient import access_resource [as 别名]
def get_api_resource():
	resource_url = raw_input("Resource relative url (/api/v1/playlists): ") or "/api/v1/playlists"
	client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
	start = time.time()
	response = client.access_resource(resource_url, ACCESS_TOKEN)
	end = time.time()
	print "\n"
	print response
	print "\nTime: %ss\n" % (end - start)
开发者ID:xmarcosx,项目名称:khan-api,代码行数:11,代码来源:test.py

示例5: get_api_resource

# 需要导入模块: from test_oauth_client import TestOAuthClient [as 别名]
# 或者: from test_oauth_client.TestOAuthClient import access_resource [as 别名]
def get_api_resource():

    resource_url = (raw_input("Resource relative url (/api/v1/playlists): ") or
                    "/api/v1/playlists")

    client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
    response = client.access_resource(resource_url, ACCESS_TOKEN)

    print "\n"
    print response
    print "\n"
开发者ID:Hao-Hsuan,项目名称:KhanLatest,代码行数:13,代码来源:test.py

示例6: get_api_resource

# 需要导入模块: from test_oauth_client import TestOAuthClient [as 别名]
# 或者: from test_oauth_client.TestOAuthClient import access_resource [as 别名]
def get_api_resource(resource_url = '/api/v1/user/exercises/scientific_notation'):

    #resource_url = '/api/v1/user/exercises/scientific_notation' #JS# raw_input("Resource relative url (/api/v1/playlists): ") \
        #or "/api/v1/playlists"
    

    client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
    start = time.time()
    response = client.access_resource(resource_url, ACCESS_TOKEN)
    end = time.time()
    return response, start, end
开发者ID:GenerationKnown,项目名称:EurlPythonServer,代码行数:13,代码来源:khanChecker.py

示例7: get_api_resource

# 需要导入模块: from test_oauth_client import TestOAuthClient [as 别名]
# 或者: from test_oauth_client.TestOAuthClient import access_resource [as 别名]
    def get_api_resource(self, resourceUrl):

        # Example URLs
        # /api/v1/user/exercises/[email protected]
        # /api/v1/[email protected]
        # /api/v1/exercises

        client = TestOAuthClient(self.SERVER_URL, self.CONSUMER_KEY, self.CONSUMER_SECRET)
        start = time.time()
        response = client.access_resource(resourceUrl, self.ACCESS_TOKEN)
        end = time.time()

        # print "\nTime: %ss\n" % (end - start)
        return response
开发者ID:biffhero,项目名称:KhanReporter,代码行数:16,代码来源:KhanOAuthConnector.py

示例8: api_call

# 需要导入模块: from test_oauth_client import TestOAuthClient [as 别名]
# 或者: from test_oauth_client.TestOAuthClient import access_resource [as 别名]
def api_call(target_version, target_api_url, debug=False, authenticate=True):
    """
    Generic API call function, that will try to use an authenticated request if available,
    otherwise will fall back to non-authenticated request.
    """
    # TODO : Use requests for both kinds of authentication.
    # usage : api_call("v1", "/badges")
    resource_url = "/api/" + target_version + target_api_url
    try:
        if authenticate and REQUEST_TOKEN and ACCESS_TOKEN:
            client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
            response = client.access_resource(resource_url, ACCESS_TOKEN)
        else:
            response = requests.get(SERVER_URL + resource_url).content
        json_object = json.loads(response)
    except Exception as e:
        print e
        return {}
    if(debug):
        print json_object
    return json_object
开发者ID:aronasorman,项目名称:khan-api-python,代码行数:23,代码来源:api_models.py

示例9: progressScrape

# 需要导入模块: from test_oauth_client import TestOAuthClient [as 别名]
# 或者: from test_oauth_client.TestOAuthClient import access_resource [as 别名]
def progressScrape():

    resource_url = "/api/v1/user/exercises/progress_changes"

    client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
    response = client.access_resource(resource_url, ACCESS_TOKEN)
    mongoclient = MongoClient()
    db = mongoclient.flexkhan

    counter = 0
    while counter == 0:
        
        parsed_json = json.loads(response)
        size = len(parsed_json)
        progress = db.progress
        
        i = 0
        while i < size:
            result = db.progress.insert_one(parsed_json[i])
            print("Check!")
            i += 1
        end = time.time()
        # print "\nTime: %ss\n" % (end - start) 
        counter = 1  
开发者ID:fjbarrett,项目名称:flexkhan,代码行数:26,代码来源:updateR.py


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