Skip to content

Instantly share code, notes, and snippets.

@ryf123
Last active February 20, 2019 19:43
Show Gist options
  • Save ryf123/199f642de272b14bd056ec390a80b64b to your computer and use it in GitHub Desktop.
Save ryf123/199f642de272b14bd056ec390a80b64b to your computer and use it in GitHub Desktop.
import requests
URL = ""
headers = {'Authorization': ''}
def send_request(zip_code, search_query):
PARAMS = {'zip_code':zip_code, 'search_query': search_query}
r = requests.get(url = URL, params = PARAMS, headers = headers)
data = 0
if r.status_code != 200:
print "status_code not 200", r
return -1
else:
data = r.json()
if 'results' in data:
if len(data['results']) == 0:
print "get empty result", data
return -1
else:
return len(data['results'])
else:
print 'results not in data', data
return -1
return data
zip_codes = [94103, 94102, 94101, 94066, 92037]
categories = ['house cleaning', 'massage', 'dj', 'plumber', 'photographer']
import random
import time
error = 0
for i in xrange(1000):
r = int(random.random() * len(zip_codes))
zip_code = zip_codes[r]
r = int(random.random() * len(categories))
category = categories[r]
start = time.time()
l = send_request(zip_code, category)
if l == -1:
error += 1
end = time.time()
print("iteration: ", i, " time:", end - start, zip_code, category, l)
time.sleep(1)
print "total error:", error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment