<commit_before>#!/usr/bin/python2

import time
import serial
import sys

temp = 0
light = 0
presence = False

def process_line(data):
    global temp
    global light
    global presence

    parts = data.split(' ')

    for part in parts:
        if part[0] == 'T':
            temp = part[1:]
        if part[0] == 'L':
            light = part[1:]
        if part[0] == 'P':
            if part[1] == '1':
                presence = True
            else:
                presence = False

    print('T%s L%s P%s' % (temp, light, presence))

def listener(argv):
    if len(argv) == 0:
        print('Not enough argument:\n python2 serial_listener.py port baudrate')
        sys.exit(1)

    ser = serial.Serial(argv[0], argv[1])

    while 1:
        data = ser.readline().strip()
        process_line(data)
    ser.close()

if __name__ == '__main__':
    listener(sys.argv[1:])<commit_msg>olimex: HTTP call to the server to store sensors data.<commit_after>#!/usr/bin/python2

import httplib
import json
import time
import serial
import sys

# configuration
server = 'http://localhost:9000'
sensorId = '1'
header = 'X-Header'

# global var containing the sensors values
temp = 0
light = 0
presence = False

def process_line(data):
    global temp
    global light
    global presence

    parts = data.split(' ')

    for part in parts:
        if part[0] == 'T':
            temp = part[1:]
        if part[0] == 'L':
            light = part[1:]
        if part[0] == 'P':
            if part[1] == '1':
                presence = True
            else:
                presence = False

    print('T%s L%s P%s' % (temp, light, presence))
    call_server(temp, light, presence)

def call_server(temp, light, presence):
    global server
    global sensorId

    data = {'values':[{'type': 'temp', 'value': temp}, {'type': 'presence', 'value': 1}, {'type': 'light', 'value': light}]}
    body = json.dumps(data)

    http = httplib.HTTPConnection('remy.io', 9005, timeout=10)
    headers = { "Content-Type": "application/json", header: 'OK' }
    http.request('POST', '/api/hit/' + sensorId, body, headers)
    http.close()

def listener(argv):
    if len(argv) == 0:
        print('Not enough argument:\n python2 serial_listener.py port baudrate')
        sys.exit(1)

    call_server(10, 5, 1)

    ser = serial.Serial(argv[0], argv[1])

    while 1:
        data = ser.readline().strip()
        process_line(data)
    ser.close()

if __name__ == '__main__':
    listener(sys.argv[1:])
{'fraction_non_alphanumeric': 0.14640994785399117, 'fraction_numerical': 0.020056157240272765, 'mean_word_length': 2.3702702702702703, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4300765', 'n_tokens_mistral': 847, 'n_tokens_neox': 809, 'n_words': 229}