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

import json
import logging
import os
import requests
from scapy.all import sniff
from scapy.all import ARP
import sys


def arp_display(pkt):
    mac = pkt[ARP].hwsrc
    if mac in [button['address'] for button in config['buttons']]:
        idx = [button['address'] for button in config['buttons']].index(mac)
        button = config['buttons'][idx]

        logging.info(button['name'])
        r = requests.post(button['url'], json=button['body'], headers=button['headers'])
        logging.info('Status Code: {}'.format(r.status_code))


# create basepath
path = os.path.dirname(os.path.realpath(__file__))

# log events in stdout and log file
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.propagate = False
format = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")

stdoutHandler = logging.StreamHandler(sys.stdout)
stdoutHandler.setFormatter(format)
logger.addHandler(stdoutHandler)

fileHandler = logging.FileHandler(path + '/dasshio.log', 'w')
fileHandler.setFormatter(format)
logger.addHandler(fileHandler)

# read config file
with open(path + '/data/options.json', mode='r') as data_file:
    config = json.load(data_file)

# start sniffing
sniff(prn=arp_display, filter='arp', store=0, count=0)<commit_msg>Added lower function to mac to match options.json<commit_after>#!/usr/bin/env python3

import json
import logging
import os
import requests
from scapy.all import sniff
from scapy.all import ARP
import sys


def arp_display(pkt):
    mac = pkt[ARP].hwsrc.lower()
    if mac in [button['address'].lower() for button in config['buttons']]:
        idx = [button['address'].lower() for button in config['buttons']].index(mac)
        button = config['buttons'][idx]

        logging.info(button['name'])
        print(button['name'], mac, "pressed!")
        print("REQUEST!!!", button['url'])
        r = requests.post(button['url'], json=button['body'], headers=button['headers'])
        logging.info('Status Code: {}'.format(r.status_code))


# create basepath
path = os.path.dirname(os.path.realpath(__file__))

# log events in stdout and log file
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.propagate = False
format = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")

stdoutHandler = logging.StreamHandler(sys.stdout)
stdoutHandler.setFormatter(format)
logger.addHandler(stdoutHandler)

fileHandler = logging.FileHandler(path + '/dasshio.log', 'w')
fileHandler.setFormatter(format)
logger.addHandler(fileHandler)

# read config file
print("Opening json file...")
with open(path + '/data/options.json', mode='r') as data_file:
    config = json.load(data_file)

# start sniffing
print("Starting sniffing...")
sniff(prn=arp_display, filter='arp', store=0, count=0)
{'fraction_non_alphanumeric': 0.15028288543140028, 'fraction_numerical': 0.0021216407355021216, 'mean_word_length': 4.968354430379747, 'pattern_counts': {'":': 0, '<': 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': '6142919', 'n_tokens_mistral': 892, 'n_tokens_neox': 887, 'n_words': 208}