def process_new_file(event): time.sleep(1) print("Initiating processing of file " + event.src_path) try: validator = Validator(event.src_path) if validator.is_valid(): parser = Parser(event.src_path) data = parser.parse() else: move_file(event.src_path, ARCHIVE_FILED_FILES) print("File %s is not valid" % event.src_path) return database = DataBase() database.store_product(data) presta_db = PrestaShopDB() presta_db.update_quantity(data.Reference, data.Stock) # post to presta # delete file # log # fail manda email print("Received created event - %s." % event.src_path) move_file(event.src_path, ARCHIVE_FILES) except Exception as e: print("Failed to process file - %s." % event.src_path) print(str(e)) move_file(event.src_path, ARCHIVE_FILED_FILES)
def index(request): reader = CsvReader('SpendingCoach/sample.csv') parser = Parser(reader) # for index, data in parser: # results.append({}) pprint.PrettyPrinter() pprint.pprint(parser.parse()) income = 0.00 expense = 0.00 for p in parser.parse(): if p['is_expense'] is True: expense += float(p['amount']) else: income += float(p['amount']) result = {"income": income, "expense": expense} return TemplateResponse(request, "dashboard.html", result)
def test_parser(self): reader = CsvReader('tests/samples/sample_statement.csv') parser = Parser(reader) pprint.PrettyPrinter() pprint.pprint(parser.parse())