class LoadAccess: ''' It allows load the data of access, before check if is posible get new data from the page, if is not posible load the data store in the database ''' def __init__(self): ''' Load the configuration ''' self.__configuration = Configuration() self.__extractor = Extractor(self.__configuration.getAccounting()) def getAccess(self, date_start=None, date_end=None, phone=None): db = DB() if(self.__checkNetwork()): db.insertAccess(self.__extractor.extract()) return db.getAccess(date_start, date_end, phone) def __checkNetwork(self): ''' It check if there are network ''' s = socket(AF_INET, SOCK_STREAM) try: s.settimeout(5) s.connect((self.__configuration.getDomain(), 80)) s.close() return True except Exception, ex: return False
class qualifieldAction(InterfaceAction): def __init__(self, parameters): self.__parameters = parameters self.__config = Configuration() def run(self): thread = qualifieldThread(self.__getManager(), self.__parameters) thread.start() return 'OK' def __getManager(self): if self.__parameters['language'] == 'plpgsql': return Postgres(self.__config.getDBHost(), self.__config.getDBPort(), self.__config.getDBUser(), self.__config.getDBPassword())
def __init__(self): ''' Load the configuration ''' self.__configuration = Configuration() self.__extractor = Extractor(self.__configuration.getAccounting())
class Request: def __init__(self): self.__config = Configuration() def send(self, action, parameters): server = HTTPConnection(host=self.__config.getWebAppHost(), port=self.__config.getWebAppPort(), timeout=5) print "Sending: '%s' to %s:%s" % (action, self.__config.getWebAppHost(), self.__config.getWebAppPort()) arguments = urllib.urlencode({'action': action, 'parameters': parameters}) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} server.request("POST", '/comunication/', arguments, headers) return server.getresponse()
def __init__(self, parameters): self.__parameters = parameters self.__config = Configuration()
def execute(self): config = Configuration() config.setDBConfiguration(self.__configuration)
# -*- coding: utf-8 -*- #!/usr/bin/python ''' Created on 28/01/2014 @author: jdsantana ''' from Common.Configuration import Configuration from Common.Socket import Socket if __name__ == '__main__': ''' Load configuration ''' config = Configuration() ''' Load Socket connection ''' socket = Socket(config.getEngineHost(), config.getEnginePort()) socket.run()
def __init__(self): self.__config = Configuration()