minor changes
This commit is contained in:
4
main.py
4
main.py
@@ -1,6 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -33,8 +31,6 @@ from chains import (
|
|||||||
shefa_birkat_hashem,
|
shefa_birkat_hashem,
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: fix problem of left-to-right printing
|
|
||||||
|
|
||||||
Path(RESULTS_DIRNAME).mkdir(exist_ok=True)
|
Path(RESULTS_DIRNAME).mkdir(exist_ok=True)
|
||||||
Path(RAW_FILES_DIRNAME).mkdir(exist_ok=True)
|
Path(RAW_FILES_DIRNAME).mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
36
promotion.py
36
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
|
:param output_filename: A given file to write to
|
||||||
"""
|
"""
|
||||||
log_message_and_time_if_debug('Writing promotions to output file')
|
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'):
|
if output_filename.endswith('.csv'):
|
||||||
encoding_file = "utf_8_sig" if sys.platform == "win32" else "utf_8"
|
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:
|
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}")
|
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.
|
This function returns a row in the promotions XLSX table.
|
||||||
|
|
||||||
:param promo: A given Promotion object
|
:param promo: A given Promotion object
|
||||||
:param item: A given item object participating in the promotion
|
:param item: A given item object participating in the promotion
|
||||||
"""
|
"""
|
||||||
return [promo.content,
|
return [
|
||||||
item.name,
|
promo.content,
|
||||||
item.price,
|
item.name,
|
||||||
promo.promo_func(item),
|
item.price,
|
||||||
(item.price - promo.promo_func(item)) / item.price,
|
promo.promo_func(item),
|
||||||
promo.club_id.name.replace('_', ' '),
|
(item.price - promo.promo_func(item)) / max(item.price, 1),
|
||||||
promo.max_qty,
|
promo.club_id.name.replace('_', ' '),
|
||||||
promo.allow_multiple_discounts,
|
promo.max_qty,
|
||||||
promo.start_date <= datetime.now(),
|
promo.allow_multiple_discounts,
|
||||||
promo.start_date,
|
promo.start_date <= datetime.now(),
|
||||||
promo.end_date,
|
promo.start_date,
|
||||||
promo.update_date,
|
promo.end_date,
|
||||||
item.manufacturer,
|
promo.update_date,
|
||||||
item.code,
|
item.manufacturer,
|
||||||
promo.reward_type.value]
|
item.code,
|
||||||
|
promo.reward_type.value,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_available_promos(chain: SupermarketChain, store_id: int, load_prices: bool, load_promos: bool) \
|
def get_available_promos(chain: SupermarketChain, store_id: int, load_prices: bool, load_promos: bool) \
|
||||||
|
Reference in New Issue
Block a user