<commit_before>"""
pandora.py

Created on Feb 27, 2014

@author: briank

@copyright: 2014 by <NAME>

@summary: Controls pandora playback thru pianobar.

When PyHouse starts initially, Pandora is inactive.

My (briank) system is controlled by an IR signal coming from an attached Pifacecad module vi lircd.

When a signal is recieved indicate the "pandora" button was pressed on a remote control,
 pianobar is fires up as a process.

Further IR signals control the pianobar process as needed, volume, next station etc.

When the remotes switches to another device (TV, BluRay, Tuner etc.), pianobar is terminated and
this module goes back to its initial state ready for another session.
"""

# Import system type stuff
import logging
from twisted.internet import protocol

from src.utils.tools import PrintBytes

g_debug = 0
g_logger = logging.getLogger('PyHouse.Pandora     ')

PB_LOC = '/usr/bin/pianobar'

#  (i) Control fifo at /home/briank/.config/pianobar/ctl opened


class PianobarControlProtocol(protocol.Protocol):
    pass


class BarProcessControl(protocol.ProcessProtocol):

    def __init__(self):
        self.m_count = 0
        pass

    def connectionMade(self):
        """Write to stdin.
        """
        # self.transport.write('')
        # self.transport.closeStdin()
        pass

    def outReceived(self, p_data):
        """Data received from stdout.

        Note: Strings seem to begin with an ansi sequence  <esc>[xxx
        # incremental time
        """
        self.m_count += 1
        l_data = p_data.rstrip('\r\n')
        l_data = l_data.lstrip(' \t')
        if l_data[0] == chr(0x1B):
            l_data = l_data[2:]
        g_logger.debug(PrintBytes(l_data))
        if l_data.startswith('2K'):  # <ESC>[2K = erase<commit_msg>debugging<commit_after>"""
pandora.py

Created on Feb 27, 2014

@author: briank

@copyright: 2014 by <NAME>

@summary: Controls pandora playback thru pianobar.

When PyHouse starts initially, Pandora is inactive.

My (briank) system is controlled by an IR signal coming from an attached Pifacecad module vi lircd.

When a signal is recieved indicate the "pandora" button was pressed on a remote control,
 pianobar is fires up as a process.

Further IR signals control the pianobar process as needed, volume, next station etc.

When the remotes switches to another device (TV, BluRay, Tuner etc.), pianobar is terminated and
this module goes back to its initial state ready for another session.
"""

# Import system type stuff
import logging
from twisted.internet import protocol

# from src.utils.tools import PrintBytes

g_debug = 0
g_logger = logging.getLogger('PyHouse.Pandora     ')

PB_LOC = '/usr/bin/pianobar'

#  (i) Control fifo at /home/briank/.config/pianobar/ctl opened


class PianobarControlProtocol(protocol.Protocol):
    pass


class BarProcessControl(protocol.ProcessProtocol):

    def __init__(self):
        self.m_count = 0
        pass

    def connectionMade(self):
        """Write to stdin.
        """
        # self.transport.write('')
        # self.transport.closeStdin()
        pass

    def outReceived(self, p_data):
        """Data received from stdout.

        Note: Strings seem to begin with an ansi sequence  <esc>[xxx
        # incremental time
        """
        self.m_count += 1
        l_data = p_data.rstrip('\r\n')
        l_data = l_data.lstrip(' \t')
        if l_data[0] == chr(0x1B):
            l_data = l_data[2:]
        # g_logger.debug("{0:} >>> {1:}".format(PrintBytes(l_data), l_data))
        if l_data[1] == 'K':  # <ESC>[nK = erase something
{'fraction_non_alphanumeric': 0.0957714925791095, 'fraction_numerical': 0.010921310557266872, 'mean_word_length': 3.045300113250283, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, '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': '4790106', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1087, 'n_words': 373}