<commit_before>#!/usr/bin/env python3

import os
from select import select
from sys import exit, stderr
from time import sleep

WRITE_BYTES = [0x0 for b in range(0, 8)]
WRITE_BYTES[0] = 0x08
WRITE_BYTES[7] = 0x02
CLOSED = 0x15
OPEN = 0x17
DOWN = 0x16

def main():
    fd_id = os.open('/dev/big_red_button', os.O_RDWR|os.O_NONBLOCK)
    fd = os.fdopen(fd_id, 'rb+')

    last = None
    return_code = 0
    try:
        while True:

            data = fd.write(bytes(WRITE_BYTES))
            data = fd.read(8)
            if data is not None and data[0] != last:
                if data[0] == CLOSED:
                    print('closed')
                elif last == DOWN and data[0] == OPEN:
                    print('up')
                elif data[0] == OPEN:
                    print('open')
                elif data[0] == DOWN:
                    print('down')
                last = data[0]
            sleep(0.1)
<commit_msg>Use vendor and product id for udev rules<commit_after>#!/usr/bin/env python3

import os
import requests
from select import select
from sys import exit, stderr
from time import sleep

WRITE_BYTES = [0x0 for b in range(0, 8)]
WRITE_BYTES[0] = 0x08
WRITE_BYTES[7] = 0x02
CLOSED = 0x15
OPEN = 0x17
DOWN = 0x16

def main():
    fd_id = os.open('/dev/big_red_button', os.O_RDWR|os.O_NONBLOCK)
    fd = os.fdopen(fd_id, 'rb+')

    last = None
    return_code = 0
    try:
        while True:

            data = fd.write(bytes(WRITE_BYTES))
            data = fd.read(8)
            if data is not None and data[0] != last:
                if data[0] == CLOSED:
                    action = 'closed'
                elif last == DOWN and data[0] == OPEN:
                    action = 'up'
                elif data[0] == OPEN:
                    action = 'open'
                elif data[0] == DOWN:
                    action = 'down'
                last = data[0]
                requests.post('http://requestb.in/ok0w6bok', data={"action": action})
            sleep(0.1)

{'fraction_non_alphanumeric': 0.11620947630922693, 'fraction_numerical': 0.03291770573566085, 'mean_word_length': 1.6675531914893618, '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': '5412904', 'n_tokens_mistral': 708, 'n_tokens_neox': 652, 'n_words': 182}