forked from stheophil/wahlversprechen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
loadtest.py
37 lines (30 loc) · 1.15 KB
/
loadtest.py
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
import json
import urllib.request
import random
import time
url = "http://192.168.56.102:9000"
def listFromJSON(path, transform):
print("Reading '" + url + urllib.request.pathname2url(path) + "'")
return map(
transform,
json.loads( urllib.request.urlopen(url + urllib.request.pathname2url(path)).read().decode("utf-8") )
)
Name = lambda x: x['name']
tags = listFromJSON("/json/tags", Name)
categories = listFromJSON("/json/categories", Name)
authors = listFromJSON("/json/authors", Name)
items = []
for author in authors:
items.extend( listFromJSON("/json/items/" + author, lambda item: item['id'] ) )
paths = ["/", "/aktuell", "/top", "/alle"]
paths.extend( map(lambda tag: urllib.request.pathname2url("/tag/" + tag), tags) )
paths.extend( map(lambda c: urllib.request.pathname2url("/category/" + c), categories) )
paths.extend( map(lambda id: urllib.request.pathname2url("/item/" + str(id)), items) )
while True:
path = random.choice( paths )
try:
request = urllib.request.urlopen(url + path)
print("Request %s [%d, %s]" % (path, request.status, request.reason))
except urllib.error.HTTPError as e:
print("Request %s: %s" % (path, e))
time.sleep(1)