<commit_before>#!/usr/bin/python
#example run: ./consumeWSevts.py localhost:8000
import websocket
import requests
import ssl

import sys

import urllib2, urllib
mydata=[('username','saltuser'),('password','<PASSWORD>'),('eauth','pam')]    #The first is the var name the second is the value
mydata=urllib.urlencode(mydata)
serverFQDN=sys.argv[1];
loginURL="http://"+serverFQDN + "/login"
print("Logging in: "+ loginURL)
req=urllib2.Request(loginURL, mydata)
req.add_header("Content-type", "application/x-www-form-urlencoded")
req.add_header("Accept", "application/x-yaml")
page=urllib2.urlopen(req).read()
print page

import yaml
doc = yaml.load(page)

token = doc.get('return')[0].get('token')

wsuri="ws://"+serverFQDN+"/ws/"
ws = websocket.WebSocket()
print("Will try creating connection to: " + wsuri+token);
ws = websocket.create_connection( wsuri + token)
ws.send('websocket client ready')

# Look at https://pypi.python.org/pypi/websocket-client/ for more
# examples.
while True:
    print ws.recv()

ws.close()<commit_msg>send login post data as json (now ython client perfectly aligned with the java one)<commit_after>#!/usr/bin/python
#example run: ./consumeWSevts.py localhost:8000
import websocket
import requests
import ssl

import sys

import urllib2, urllib
import json

mydata=[('username','saltuser'),('password','<PASSWORD>'),('eauth','pam')]   
mydata=urllib.urlencode(mydata)
myjsondata={
'username':'saltuser',
'password':'<PASSWORD>',
'eauth':'pam'
}

serverFQDN=sys.argv[1];
loginURL="http://"+serverFQDN + "/login"
print("Logging in: "+ loginURL)


req=urllib2.Request(loginURL, json.dumps(myjsondata))
req.add_header("Content-type", "application/json")
#req=urllib2.Request(loginURL, mydata)
#req.add_header("Content-type", "application/x-www-form-urlencoded")

req.add_header("Accept", "application/json")
page=urllib2.urlopen(req).read()
print page

import yaml
doc = yaml.load(page)

token = doc.get('return')[0].get('token')

wsuri="ws://"+serverFQDN+"/ws/"
ws = websocket.WebSocket()
print("Will try creating connection to: " + wsuri+token);
ws = websocket.create_connection( wsuri + token)
ws.send('websocket client ready')

# Look at https://pypi.python.org/pypi/websocket-client/ for more
# examples.
while True:
    print ws.recv()

ws.close()
{'fraction_non_alphanumeric': 0.17223198594024605, 'fraction_numerical': 0.008347978910369069, 'mean_word_length': 6.251592356687898, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 2, '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': '3940756', 'n_tokens_mistral': 840, 'n_tokens_neox': 810, 'n_words': 166}