本文整理汇总了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"]
示例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)
示例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
示例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)
示例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"
示例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
示例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
示例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
示例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