From 1a88ed6e01670a4495514e10eedb2b645df2f558 Mon Sep 17 00:00:00 2001 From: KorenLazar Date: Mon, 16 Aug 2021 23:08:04 +0300 Subject: [PATCH] minor changes --- main.py | 4 ---- promotion.py | 36 +++++++++++++++++++----------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/main.py b/main.py index 84736ea..6baeb30 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,4 @@ import os -import sys -import time from argparse import ArgumentParser from datetime import datetime from pathlib import Path @@ -33,8 +31,6 @@ from chains import ( shefa_birkat_hashem, ) -# TODO: fix problem of left-to-right printing - Path(RESULTS_DIRNAME).mkdir(exist_ok=True) Path(RAW_FILES_DIRNAME).mkdir(exist_ok=True) diff --git a/promotion.py b/promotion.py index c02e9d4..9ee2bd6 100644 --- a/promotion.py +++ b/promotion.py @@ -101,7 +101,7 @@ def write_promotions_to_csv(promotions: List[Promotion], output_filename: str) - :param output_filename: A given file to write to """ log_message_and_time_if_debug('Writing promotions to output file') - rows = [get_promotion_row_for_csv(promo, item) for promo in promotions for item in promo.items] + rows = [get_promotion_row_for_table(promo, item) for promo in promotions for item in promo.items] if output_filename.endswith('.csv'): encoding_file = "utf_8_sig" if sys.platform == "win32" else "utf_8" with open(output_filename, mode='w', newline='', encoding=encoding_file) as f_out: @@ -138,28 +138,30 @@ def write_promotions_to_csv(promotions: List[Promotion], output_filename: str) - raise ValueError(f"The given output file has an invalid extension:\n{output_filename}") -def get_promotion_row_for_csv(promo: Promotion, item: Item): +def get_promotion_row_for_table(promo: Promotion, item: Item) -> List: """ This function returns a row in the promotions XLSX table. :param promo: A given Promotion object :param item: A given item object participating in the promotion """ - return [promo.content, - item.name, - item.price, - promo.promo_func(item), - (item.price - promo.promo_func(item)) / item.price, - promo.club_id.name.replace('_', ' '), - promo.max_qty, - promo.allow_multiple_discounts, - promo.start_date <= datetime.now(), - promo.start_date, - promo.end_date, - promo.update_date, - item.manufacturer, - item.code, - promo.reward_type.value] + return [ + promo.content, + item.name, + item.price, + promo.promo_func(item), + (item.price - promo.promo_func(item)) / max(item.price, 1), + promo.club_id.name.replace('_', ' '), + promo.max_qty, + promo.allow_multiple_discounts, + promo.start_date <= datetime.now(), + promo.start_date, + promo.end_date, + promo.update_date, + item.manufacturer, + item.code, + promo.reward_type.value, + ] def get_available_promos(chain: SupermarketChain, store_id: int, load_prices: bool, load_promos: bool) \