<commit_before>import argparse                         # For parsing command line arguments
import sys                              # For importing from parent directory
import os                               # For importing from parent directory
import httplib                          # For making http requests to Vera 
import json                             # For reading JSON returned from Vera
import time                             # For timestamp

class ZwaveClient(object):

    def __init__(self, IP, PORT, channels):
        self.IP = IP
        self.PORT = PORT
        self.channels = channels

    def getData(self):
        """ Gets data from vera and formats it into internal json structure """
        current_time = time.time()
        data = self.__getJsonData()

        if data:
            device_data = []
            for device in data:
                device_name = device["name"]
                channel_data = {}
                if device_name == self.name:
                    device_data = self._formatChannelData(current_time, device, device_name)
                    return device_data
        else:
            return None

        # If the device was not found, raise an error
        raise KeyError(self.name + " was not found when querying the Vera.")

    """ Functions that must be implemented by children """
    def _formatChannelData(device):
        raise NotImplementedError("Classes that inherit from ZwaveClient must implement _formatChannelData")

    """ Functions Called within VeraClient """
    def __connect(self):
        self.connection = httplib.HTTPConnection(self.IP, self.PORT)

    def __getJsonData(self):
        """ Gets data in json format from Vera (Zwave Receiver) """
        device_data = {}
        channel_data = self.__getDeviceData()
        if channel_data:
            json_chan_data = json.loads(channel_data)
            return json_chan_data["devices"]
        else:
            return None

    def __getDeviceData(self):
        self.__connect()
        url = "/data_request?id=sdata&output_format=json"
        self.connection.request("GET", url)
        response = self.__receive()
        self.connection.close()
        if response:
            return response.read()
        else:
            return None

    def __receive(self):
        try:<commit_msg>Made ZwaveClient resilient ot internet breakage<commit_after>import argparse                         # For parsing command line arguments
import sys                              # For importing from parent directory
import os                               # For importing from parent directory
import httplib                          # For making http requests to Vera 
import json                             # For reading JSON returned from Vera
import time                             # For timestamp

class ZwaveClient(object):

    def __init__(self, IP, PORT, channels):
        self.IP = IP
        self.PORT = PORT
        self.channels = channels

    def getData(self):
        """ Gets data from vera and formats it into internal json structure """
        current_time = time.time()
        data = self.__getJsonData()

        if data:
            device_data = []
            for device in data:
                device_name = device["name"]
                channel_data = {}
                if device_name == self.name:
                    device_data = self._formatChannelData(current_time, device, device_name)
                    return device_data
        else:
            return None

        # If the device was not found, raise an error
        raise KeyError(self.name + " was not found when querying the Vera.")

    """ Functions that must be implemented by children """
    def _formatChannelData(device):
        raise NotImplementedError("Classes that inherit from ZwaveClient must implement _formatChannelData")

    """ Functions Called within VeraClient """
    def __connect(self):
        self.connection = httplib.HTTPConnection(self.IP, self.PORT)

    def __getJsonData(self):
        """ Gets data in json format from Vera (Zwave Receiver) """
        device_data = {}
        channel_data = self.__getDeviceData()
        if channel_data:
            json_chan_data = json.loads(channel_data)
            return json_chan_data["devices"]
        else:
            return None

    def __getDeviceData(self):
        try:
            self.__connect()
            url = "/data_request?id=sdata&output_format=json"
            self.connection.request("GET", url)
            response = self.__receive()
            self.connection.close()
        except IOError, detail:
            return None

        if response:
            return response.read()
        else:
            return None

    def __receive(self):
        try:
{'fraction_non_alphanumeric': 0.07142857142857142, 'fraction_numerical': 0.0, 'mean_word_length': 1.7779063042220937, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1179854', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1114, 'n_words': 372}