<commit_before>import socket
import logging
from math import ceil

from numpy import mean

from .inputdevice import InputDevice


class HDDTemp(InputDevice):
    """
    Class to access hddtemp data, through the daemon hddtemp uses.
    Requires that you actually run the hddtemp daemon
    on the localhost with the default port.
    """

    def __init__(self, host='127.0.0.1', port=7634):
        self.host = host
        self.port = port
        self.socket = socket.socket()
        self.available = False
        self.open_socket()

    def get_temp(self):
        """
        Get and parse HDD temperatures.
        Works for whatever number of HDD's you might have.
        If the daemon itself returns proper data that is.
        """
        temps = list()

        if self.available:
            data = self.try_read()

            try:
                temperature = data.decode('utf-8').split('||')
            except UnicodeDecodeError:
                temperature = []
                logging.error('hddtemp returned utterly invalid data.')
                self.available = False  # Disable reading from this source in the future.

            for temp in temperature:
                if temp[0] == '|':
                    temp = temp[1:]

                try:
                    temps.append(float(temp.split('|')[2]))
                except:
                    """
                    TODO: figure out what exception can the above actually throw...
                    """
                    logging.info('something broke.')
                    temps.append(float(0))
        else:
            logging.warning('hddtemp daemon not availible. Is it running?')

        if not temps:
            return 0
        else:
            return ceil(mean(temps))

    def open_socket(self):
        """
            Basic test to determine availibility of the daemon.
            If not availible, log it.
        """
        try:
            self.socket.connect((self.host, self.port))
            self.available = True
        except socket.error:
            self.available = False<commit_msg>aaaand a quick bugfix. an exception here should not kill the app dammit!<commit_after>import socket
import logging
from math import ceil

from numpy import mean

from .inputdevice import InputDevice


class HDDTemp(InputDevice):
    """
    Class to access hddtemp data, through the daemon hddtemp uses.
    Requires that you actually run the hddtemp daemon
    on the localhost with the default port.
    """

    def __init__(self, host='127.0.0.1', port=7634):
        self.host = host
        self.port = port
        self.socket = socket.socket()
        self.available = False
        self.open_socket()

    def get_temp(self):
        """
        Get and parse HDD temperatures.
        Works for whatever number of HDD's you might have.
        If the daemon itself returns proper data that is.
        """
        temps = list()

        if self.available:
            data = self.try_read()

            try:
                temperature = data.decode('utf-8').split('||')
            except UnicodeDecodeError:
                temperature = []
                logging.error('hddtemp returned utterly invalid data.')
                self.available = False  # Disable reading from this source in the future.

            for temp in temperature:
                try:
                    if temp[0] == '|':
                        temp = temp[1:]
                    temps.append(float(temp.split('|')[2]))
                except:
                    """
                    TODO: figure out what exception can the above actually throw...
                    """
                    logging.info('something broke.')
                    temps.append(float(0))
        else:
            logging.warning('hddtemp daemon not availible. Is it running?')

        if not temps:
            return 0
        else:
            return ceil(mean(temps))

    def open_socket(self):
        """
            Basic test to determine availibility of the daemon.
            If not availible, log it.
        """
        try:
            self.socket.connect((self.host, self.port))
            self.available = True
        except socket.error:
            self.available = False
{'fraction_non_alphanumeric': 0.08648901355773726, 'fraction_numerical': 0.0074801309022907905, 'mean_word_length': 1.542483660130719, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2855306', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1049, 'n_words': 355}