<commit_before>import httplib, urllib, hashlib
import time, sys, getopt
from urlparse import urlparse

API_VERSION = '1'

def usage():
	print """USAGE: 
  python client.py URL sharedSecret trackerid param1key param1value param2key param2value ...
EXAMPLE:
  python client.py http://localhost:8000/events VerySecret1 490154203237518 latitude 4916.46,N longitude 12311.12,W"""
  
def makeQuery(url, content):
	headers = {
		'Content-type': 'application/x-www-form-urlencoded',
		'User-Agent': 'RuuviTracker test client/1.0',
	}

	connection = httplib.HTTPConnection(url.hostname, url.port)
	connection.request("POST", url.path, urllib.urlencode(content), headers)
	response = connection.getresponse()
	print("%s %s" % (response.status, response.reason))
	connection.close()

def computeMac(data, sharedSecret):
  m = hashlib.sha1()
  for key in sorted(data.iterkeys()):
    value = data[key]
    m.update(key)
    m.update(':')
    m.update(value)
    m.update('|')
  m.update(sharedSecret)
  return m.hexdigest()
  
def createContent(data, sharedSecret, trackerid):
  data['version'] = API_VERSION
  data['trackerid'] = trackerid
  data['time'] = time.strftime('%Y-%m-%dT%H:%M:%S.000')
  data['mac'] = computeMac(data, sharedSecret)
  return data

if __name__ == '__main__':
  if len(sys.argv) < 4:
    usage()
    sys.exit(1)

  url = urlparse(sys.argv[1])
  sharedSecret = sys.argv[2]
  trackerid = sys.argv[3]
  
  fields = sys.argv[4:]
  data = {}
  for item in zip(fields, fields[1:])[::2]:
    data[item[0]]=item[1]
    
  content = createContent(data,sharedSecret, trackerid)
  makeQuery(url, content)<commit_msg>updated test-utils/client.py to match latest API<commit_after>import httplib, urllib, hashlib
import time, sys, getopt
from urlparse import urlparse

API_VERSION = '1'

def usage():
	print """USAGE: 
  python client.py URL sharedSecret trackerCode param1key param1value param2key param2value ...
EXAMPLE:
  python client.py http://localhost:8080/api/v1/events VerySecret1 490154203237518 latitude 4916.46,N longitude 12311.12,W"""
  
def makeQuery(url, content):
	headers = {
		'Content-type': 'application/x-www-form-urlencoded',
		'User-Agent': 'RuuviTracker test client/1.0',
	}

	connection = httplib.HTTPConnection(url.hostname, url.port)
	connection.request("POST", url.path, urllib.urlencode(content), headers)
	response = connection.getresponse()
	print("%s %s" % (response.status, response.reason))
	connection.close()

def computeMac(data, sharedSecret):
  m = hashlib.sha1()
  for key in sorted(data.iterkeys()):
    value = data[key]
    m.update(key)
    m.update(':')
    m.update(value)
    m.update('|')
  m.update(sharedSecret)
  return m.hexdigest()
  
def createContent(data, sharedSecret, trackerCode):
  data['version'] = API_VERSION
  data['tracker_code'] = trackerCode
  data['time'] = time.strftime('%Y-%m-%dT%H:%M:%S.000')
  data['mac'] = computeMac(data, sharedSecret)
  return data

if __name__ == '__main__':
  if len(sys.argv) < 4:
    usage()
    sys.exit(1)

  url = urlparse(sys.argv[1])
  sharedSecret = sys.argv[2]
  trackerCode = sys.argv[3]
  
  fields = sys.argv[4:]
  data = {}
  for item in zip(fields, fields[1:])[::2]:
    data[item[0]]=item[1]
    
  content = createContent(data,sharedSecret, trackerCode)
  makeQuery(url, content)
{'fraction_non_alphanumeric': 0.1521409049498937, 'fraction_numerical': 0.03310051624658366, 'mean_word_length': 4.4808652246256235, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3473802', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1164, 'n_words': 248}