def __init__(self, config): self.buff_size = config['general']['data_buffer_size'] self.output = config['general']['data_format'] self.counter = 0 self.buffer = [] self.data_handler = DataHandler(config) if 'csv' in self.output: logging_util.configure_logging('logging_config_csv.yaml') self.logger_csv = logging_util.get_logger('data_manager_csv') self.logger_csv.handlers[ 0].rotator = self.data_handler.data_logger_rotator self.logger_csv.handlers[ 0].namer = self.data_handler.data_logger_namer if 'json' in self.output: logging_util.configure_logging('logging_config_json.yaml') self.logger_json = logging_util.get_logger('data_manager_json') self.logger_json.handlers[ 0].rotator = self.data_handler.data_logger_rotator self.logger_json.handlers[ 0].namer = self.data_handler.data_logger_namer
def start_watching(): event_handler = Event() observer = Observer() observer.schedule(event_handler, source_path, recursive=True) observer.start() logger.info('Started Monitoring') check_and_create_folders() move_file() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join() config_options = ConfigOptions() destination_path = config_options.get_destination_path() source_path = config_options.get_source_path() dir_categories = config_options.get_categories() file_classification = dict(config_options.get_file_classification()) logging_util.init(config_options.get_log_config_file()) logger = logging_util.get_logger(__name__) start_watching()
#!/usr/bin/env python3 import logging_util # instantiate at module level, not class level # https://stackoverflow.com/questions/22807972/python-best-practice-in-terms-of-logging logger = logging_util.get_logger(__name__) class Fibonacci: """ https://en.wikipedia.org/wiki/Fibonacci_number Uses memoization to store previous results in a dictionary and reduce execution time https://en.wikipedia.org/wiki/Memoization """ def __init__(self): # memoized results of numbers in fibonacci sequence # Could use an array. This could save some memory use index instead of key. # Use dictionary, more general memoization solution and probably a little more convenient. # e.g. dictionary.get(n) is safer and easier than avoiding index out of bounds # key: value == n: fib(n) # seed with fib(0), fib(1) self.results = {0: 0, 1: 1} def fibonacci(self, n: int) -> int: """ :param n: an integer >= 0 :return: Fibonacci number