本文整理汇总了Python中unirest.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _dispatch
def _dispatch(self, urls):
with self.lock:
for link in urls:
# Avoid exploring the same page twice.
if link in self.seen:
continue
try:
# TODO: Should be removed in final version.
# If it's a local file, just go ahead and read the file.
if link.startswith('/'):
class ResponseDummy:
def __init__(self, file):
self.body = open(file)
syncCB = partial(self._callback, self.router.match(link))
Thread(target=syncCB, args=(link, ResponseDummy(link))).start()
# TODO: stop removing dummy code here.
else:
# Request page contents asynchronously.
get(link, callback=partial(self._callback, self.router.match(link), link))
self.seen.add(link)
self.pending += 1
except Router.NoMatchError as e:
print 'Could not find handler endpoint for {0}.'.format(str(e))
示例2: describeImage
def describeImage(imgPath):
response = unirest.post("https://camfind.p.mashape.com/image_requests",
headers={
"X-Mashape-Key": "You meshape key, register at meshape https://market.mashape.com/imagesearcher/camfind"
},
params={
"image_request[image]": open(imgPath, mode="r"),
"image_request[language]": "en",
"image_request[locale]": "en_US"
}
)
token=response.body['token']
response = unirest.get("https://camfind.p.mashape.com/image_responses/" + token,
headers={
"X-Mashape-Key": "aiYZkTIXj7mshNul9uy1GrEoIZYOp1QdFbGjsn3AexvpbfgD3g",
"Accept": "application/json"
}
)
while (response.body['status']!="completed" and response.body['status']!="skipped"):
time.sleep(1) #sleep for 1 seconds
response = unirest.get("https://camfind.p.mashape.com/image_responses/" + token,
headers={
"X-Mashape-Key": "aiYZkTIXj7mshNul9uy1GrEoIZYOp1QdFbGjsn3AexvpbfgD3g",
"Accept": "application/json"
}
)
#assume completed
if (response.body['status']!="skipped"):
return response.body['name']
else:
return "unsuccessful"
示例3: identify_image
def identify_image(inputFileURL):
response = unirest.post("https://camfind.p.mashape.com/image_requests",
headers={
"X-Mashape-Key": "9UyIuOYhCKmshb72Y27ctmWYJReGp1G3LaBjsndZ3QPhPjjHMl"
},
params={
"focus[x]": "480",
"focus[y]": "480",
"image_request[language]": "en",
"image_request[locale]": "en_US",
"image_request[remote_image_url]": ""+str(inputFileURL)+""
}
)
token = response.body['token'] # The parsed response
print token
response2 = unirest.get("https://camfind.p.mashape.com/image_responses/"+str(token),
headers={
"X-Mashape-Key": "9UyIuOYhCKmshb72Y27ctmWYJReGp1G3LaBjsndZ3QPhPjjHMl"
}
)
time.sleep(1)
while (response2.body['status'] == 'not completed'):
response2 = unirest.get("https://camfind.p.mashape.com/image_responses/"+str(token),
headers={
"X-Mashape-Key": "9UyIuOYhCKmshb72Y27ctmWYJReGp1G3LaBjsndZ3QPhPjjHMl"
}
)
print "Sleeping"
time.sleep(1)
#print response2.body
print response2.raw_body
示例4: detail_view
def detail_view(request, recipe_id, ingredients):
ingredients = ingredients.split('+') # list of ingredients owned
response = unirest.get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/" + recipe_id + "/information",
headers={
"X-Mashape-Key": "QN5CLcAiQXmshOrib4vl7QifQAPjp1MjXoijsnsKdgztp93FnI"
}
)
needed = []
for ingredient in response.body["extendedIngredients"]:
needed.append(ingredient["name"])
missing = list(set(needed) - set(ingredients))
print missing
recipe = unirest.get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/extract?forceExtraction=false&url=http%3A%2F%2F" + response.body['sourceUrl'][7:].replace("/", "%2F") + "",
headers={
"X-Mashape-Key": "QN5CLcAiQXmshOrib4vl7QifQAPjp1MjXoijsnsKdgztp93FnI"
}
)
context = {
'recipe': response.body,
'directions': recipe.body
}
return render(request, 'recipe_detail.html', context)
示例5: get_information
def get_information(url):
"""Get information for url using webscraping and API calls."""
all_info = []
scrape_info = get_all_recipe_info(url)
response1 = unirest.get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/extract?forceExtraction=false&url=%s" % url,
headers={
"X-Mashape-Key": os.environ['MASHAPE_KEY']
}
)
api_info = response1.body
recipe_api_id = api_info['id']
#instructions for recipe through api request
response2 = unirest.get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/%s/analyzedInstructions?stepBreakdown=true" % recipe_api_id,
headers={
"X-Mashape-Key": os.environ['MASHAPE_KEY'],
"Accept": "application/json"
}
)
instruction_info = response2.body[0]['steps']
all_info.append(scrape_info)
all_info.append(api_info)
all_info.append(instruction_info)
return all_info
示例6: get_class_collection
def get_class_collection(player_class):
response = unirest.get(
"https://omgvamp-hearthstone-v1.p.mashape.com/cards/classes/" + player_class + "?collectible=1",
headers={"X-Mashape-Key": "HFXwiln4KJmshs6B1jOMfsA75kg3p1Jj1qOjsntjBvnGaWzx1v"},
)
classCards = json.dumps(response.body, indent=1, separators=(",", ": "))
classCardsDict = json.loads(classCards)
removeHeroes = list()
for x in classCardsDict:
if x["type"] != "Hero":
removeHeroes.append(x)
response2 = unirest.get(
"https://omgvamp-hearthstone-v1.p.mashape.com/cards/types/Minion?collectible=1",
headers={"X-Mashape-Key": "HFXwiln4KJmshs6B1jOMfsA75kg3p1Jj1qOjsntjBvnGaWzx1v"},
)
minionCards = json.dumps(response2.body, indent=1, separators=(",", ": "))
minionCardsDict = json.loads(minionCards)
neutralCardsDict = list()
for y in minionCardsDict:
if "playerClass" not in y:
neutralCardsDict.append(y)
collection = removeHeroes + neutralCardsDict
return collection
示例7: __init__
def __init__(self, url):
self.tournaments_data, self.return_code = json.dumps(unirest.get(url, headers={"Accept":"application/json"}).body), \
unirest.get(url).code
checkCode(self.return_code)
self.parsed_data = json.loads(self.tournaments_data)
self.past = {}
self.setTournamentsAttributes(self.parsed_data)
示例8: __init__
def __init__(self, name, url):
self.name = name
self.player_data, self.return_code = json.dumps(unirest.get('http://' + url, header={"Accept":"application/json"}).body), \
unirest.get('http://' + url).code
checkCode(self.return_code)
parsed_data = json.loads(self.player_data)
self.dict_name=''
self.setPlayerAttributes(parsed_data)
示例9: question
def question(qid):
url = settings.API_URL + 'question/' + qid
response = unirest.get(url, headers={'Content-Type':'application/json'}, params={'embedded':'{"post":1}'})
answers = unirest.get(settings.API_URL + 'answer/?question=' + qid, headers={'Content-Type':'application/json'})
response.body['answer'] = answers.body['data']
response.body['nAnswers'] = len(response.body['answer'])
return render_template('question.html', data=response.body)
示例10: test_timeout
def test_timeout(self):
unirest.timeout(3)
response = unirest.get("http://httpbin.org/delay/1")
self.assertEqual(response.code, 200)
unirest.timeout(1)
try:
response = unirest.get("http://httpbin.org/delay/3")
self.fail("The timeout didn't work")
except:
pass
示例11: runApiRequest
def runApiRequest(self,request):
"""
Method that run a api request
"""
#print "Getting information..."
#We launch a first request
try:
self.response = unirest.get(request,
headers={
"X-Mashape-Key": self.apiKey,
"Accept": "text/plain"
}
)
#print "OK"
except Exception:
print "Error! Can't get any response from the api!"
#if there is a response
if self.response != None:
#if this response is good
if self.response.code == 200:
#we notify the user that the request was successful
return True
else:
#else we try again for a fixed number of try
numberOfTry=1
while (numberOfTry <self.maxTry):
print "Try number {0}".format(numberOfTry)
time.sleep(self.timeout)
try:
self.response = unirest.get(request,
headers={
"X-Mashape-Key": self.apiKey,
"Accept": "text/plain"
}
)
if self.response.code == 200:
return True
except Exception:
print "Failed ! Try again in {0} secs".format(self.timeout)
numberOfTry+=1
return False
示例12: __init__
def __init__(self, urls):
stats_data, self.return_code = unirest.get(urls[0], headers={"Accept":"application/json"}).body['data'], \
unirest.get(urls[0]).code
checkCode(self.return_code)
for url in urls:
self.return_code = unirest.get(url).code
checkCode(self.return_code)
if urls.index(url) == 0:
continue
stats_data += unirest.get(url, headers={"Accept":"application/json"}).body['data']
self.setStats(stats_data)
self.stats = stats_data
print 'Retreived information for ' + str(len(stats_data)) + ' players.'
示例13: run
def run(self):
print "Base Worker Listening"
while 1:
# print "Hey Im working"
#Keep listening there is no customer yet in store
if orderQueue.empty():
#Chill
time.sleep(random.randint(10, 100) / 80.0)
continue
else:
#Hey there is a Customer in my shop.
item = self.__queue.get()
#for demo sleep
time.sleep(random.randint(10, 100) / 50.0)
#parse to get Customer Info
customer_channel = parseInfo(item)
print "Connecting to "+customer_channel
print "Asking Customer (Burrito/Bowl)"
#for demo sleep
time.sleep(random.randint(10, 100) / 50.0)
#Lets ask him his requirements Burrito/Bowl
responseBase = unirest.get("http://"+customer_channel+"/getBase", headers={ "Accept": "application/json" },
params={ "base": "Tortilla/Bowl" })
#If customer replies with his choice, Process order and send to next worker
if responseBase.code==200:
print "I will add Delicious "+responseBase.body+" for you !"
baseValue = responseBase.body
print "Asking Customer (Brown/White Rice)"
#for demo sleep
time.sleep(random.randint(10, 100) / 50.0)
#Lets ask user which type of Rice he wants.
responseRice = unirest.get("http://"+customer_channel+"/getRice", headers={ "Accept": "application/json" },
params={ "rice": "Brown,White" })
#If customer replies with his choice, Process order and send to next worker
if responseRice.code==200:
print "I will add Delicious "+responseRice.body+" for you !"
self.cursor = self.connection.cursor()
self.cursor.execute("INSERT INTO Orders(CustomerName, Stage ) VALUES ( '{0}', '{1}')".format(parseCustomerInfo(item),"1"))
self.connection.commit()
self.cursor.close()
riceValue = responseRice.body
sendToNextWorker(item,baseValue,riceValue)
示例14: test_not_your_objects
def test_not_your_objects():
first_image_response = unirest.post(hostname + '/enroll-image/',
params={"image": open("./arnold.jpg", mode="r"), "label":"Arnold Schwarzenegger"})
assert first_image_response.code == 200
training_set_id = first_image_response.body['id']
training_set_response = unirest.get(hostname + '/trainingset/' + training_set_id + '/')
assert training_set_response.code == 200
unirest.clear_default_headers()
random_username = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8))
permissions_response = unirest.get(hostname + '/trainingset/' + training_set_id + '/',
headers={"X-Mashape-User":random_username, "X-Mashape-Proxy-Secret":"DEBUG"})
print permissions_response.code
print permissions_response.body
assert permissions_response.code != 200
示例15: getData
def getData(name):
try:
print "fetching " + name + " data..."
get_data = unirest.get("https://vikhyat-hummingbird-v2.p.mashape.com/anime/" + name,
headers={"X-Mashape-Key": "key"})
if(get_data.code == 404):
name = re.sub('s-', '-s-', name, 1)
print "trying " + name + "..."
get_data = unirest.get("https://vikhyat-hummingbird-v2.p.mashape.com/anime/" + name,
headers={"X-Mashape-Key": "key"})
return get_data
except Exception as err:
print err()
return None