def test_make_directory(self): InitializeDirectory.make_directory() assert True \ if os.path.isdir("../scrapes") == True \ and os.path.isdir("../scrapes/" + date) == True \ else False
class LogMain(): """ Decorator for logging URS runtime. Also handles KeyboardInterrupt and adds the event to the log if applicable. """ ### Makes directory in which the log and scraped files will be stored. InitializeDirectory.make_directory() ### Set directory path and log format. DIR_PATH = "../scrapes/%s" % date LOG_FORMAT = "[%(asctime)s] [%(levelname)s]: %(message)s" ### Configure logging settings. logging.basicConfig( filename = DIR_PATH + "/urs.log", format = LOG_FORMAT, level = logging.INFO ) @staticmethod def master_timer(function): """ Wrapper for logging the amount of time it took to execute main(). Handle KeyboardInterrupt if user cancels URS. Parameters ---------- function: function() Run method within the wrapper Exceptions ---------- KeyboardInterrupt: Raised if user cancels URS Returns ------- wrapper: function() Return the wrapper method that runs the method passed into the decorator """ def wrapper(*args): logging.info("INITIALIZING URS.") logging.info("") start = time.time() try: function(*args) except KeyboardInterrupt: print(Style.BRIGHT + Fore.RED + "\n\nURS ABORTED BY USER.\n") logging.warning("") logging.warning("URS ABORTED BY USER.\n") quit() logging.info("URS COMPLETED IN %.2f SECONDS.\n" % (time.time() - start)) return wrapper