-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
37 lines (28 loc) · 958 Bytes
/
test.py
File metadata and controls
37 lines (28 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from __future__ import division
from time import sleep
import httplib2
import json
h = httplib2.Http()
url = raw_input("Please enter the uri you want to access: ")
if url == '':
url = 'http://localhost:8080/api/v1/users'
req_per_minute = float(raw_input("Please specify the number of requests per minute: ") )
interval = (60.0 / req_per_minute)
def SendRequests(url, req_per_minute):
requests = 0
while requests < req_per_minute:
result = json.loads(h.request(url,'GET')[1])
#result = h.request(url,'GET')[1]
#print result
if result.get('error') is not None:
print "Error #%s : %s" %(result.get('error'), result.get('data'))
print "Hit rate limit. Waiting 5 seconds and trying again..."
sleep(5)
SendRequests(url, req_per_minute)
else:
print "Number of Requests: ", requests+1
print result.get('response')
requests = requests + 1
sleep(interval)
print "Sending Requests..."
SendRequests(url, req_per_minute)