Beispiel #1
0
class ContentMonitor(Task):
    def __init__(self, config=None):
        self.__config()
        self.logger = Logger()
        if (config == None):
            self.configHandler = AgentConfigHandler("./agents/content")
        else:
            self.configHandler = AgentConfigHandler("./agents/content", config)
        self.seleniumBroker = SeleniumBroker()

    def execute(self):
        for config in self.configHandler.getJobsConfig():
            self.seleniumBroker.getSearchOutput(config)
        self.logger.getLogger(__name__).debug('Content Monitor is executing')

    def __config(self):
        pass

    def action(self):
        pass
Beispiel #2
0
class AgentConfigHandler:
    def __init__(self, configFolderPath, configFilePath=None):
        self.logger = Logger()
        self.jobConfigList = []

        if (configFilePath == None):
            self.__loadConfigFromAFolder(configFolderPath)
        else:
            self.__loadConfigFromAFile(configFilePath)

    def __loadConfigFromAFile(self, configFilePath):
        try:
            with open(configFilePath, "r") as read_file:
                try:
                    config = json.load(read_file)
                except:
                    self.logger.getLogger(__name__).error(
                        'Inccorect Json file ' + configFilePath)
                    return
                self.jobConfigList.append(config)
        except:
            self.logger.getLogger(__name__).error('File not found !! ' +
                                                  configFilePath)
            return

    def __loadConfigFromAFolder(self, configFolderPath):
        for r, d, f in os.walk(configFolderPath):
            for file in f:
                if '.json' in file:
                    with open(configFolderPath + "/" + file, "r") as read_file:
                        try:
                            config = json.load(read_file)
                        except:
                            self.logger.getLogger(
                                __name__).error('Inccorect Json file ' +
                                                configFolderPath + "/" + file)
                            continue
                        self.jobConfigList.append(config)

    def getJobsConfig(self):
        return self.jobConfigList