aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-10-18 22:48:44 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-10-18 22:48:44 -0700
commitc686a4f045f15944940e131ccfb2fa6a1e0a5e7c (patch)
treeb7ac9aa375c7c55df2a32e530da29edb9f7abc9e
parente547d716bb5c49986c2e682a934b2aa6dbd74fde (diff)
downloadtraccar-server-c686a4f045f15944940e131ccfb2fa6a1e0a5e7c.tar.gz
traccar-server-c686a4f045f15944940e131ccfb2fa6a1e0a5e7c.tar.bz2
traccar-server-c686a4f045f15944940e131ccfb2fa6a1e0a5e7c.zip
Script to test map
-rwxr-xr-xtools/test-map.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/test-map.py b/tools/test-map.py
new file mode 100755
index 000000000..0568b283e
--- /dev/null
+++ b/tools/test-map.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+
+import urllib
+import urllib2
+import httplib
+import random
+import json
+
+server = 'localhost:5055'
+baseUrl = 'http://localhost:8082'
+user = { 'email' : 'admin', 'password' : 'admin' }
+devices = 500
+
+def login():
+ request = urllib2.Request(baseUrl + '/api/session')
+ response = urllib2.urlopen(request, urllib.urlencode(user))
+ return response.headers.get('Set-Cookie')
+
+def add_device(cookie, unique_id):
+ request = urllib2.Request(baseUrl + '/api/devices')
+ request.add_header('Cookie', cookie)
+ request.add_header('Content-Type', 'application/json')
+ device = { 'name' : unique_id, 'uniqueId' : unique_id }
+ response = urllib2.urlopen(request, json.dumps(device))
+ data = json.load(response)
+ return data['id']
+
+def send_message(conn, device_id):
+ params = (('id', device_id), ('lat', random.uniform(59, 61)), ('lon', random.uniform(29, 31)))
+ conn.request('GET', '?' + urllib.urlencode(params))
+ conn.getresponse().read()
+
+cookie = login()
+conn = httplib.HTTPConnection(server)
+
+for i in range(devices):
+ device_id = "{0:0>6}".format(i)
+ add_device(cookie, device_id)
+ send_message(conn, device_id)