Fixed the bug with cerberus_web_client.py by working with Selenium. To login each chain working with it must have a username for login with Selenium. in this mechanism, a path to a gz file is returned instead of url
Added the option to output a prices json file in main.py under --prices-with-promos, where the prices are updated by the latest promotions (under the 'final_price' key, where 'price' represents the price before promotions). Fixed small bug of BinaWebCleint by checking that filename does not contain 'null'. Changed Hierarchy of chains such that it includes the webclients. Added the date to the output filenames to start storing the data over time. Black formatting (according to pip 8 guidelines). Changed the chains_dict in main to a constant one.
This commit is contained in:
@@ -8,14 +8,16 @@ from supermarket_chain import SupermarketChain
|
||||
FNAME_KEY = "FileNm"
|
||||
|
||||
|
||||
class BinaProjectWebClient:
|
||||
class BinaProjectWebClient(SupermarketChain):
|
||||
_date_hour_format = '%Y-%m-%d %H:%M:%S'
|
||||
_update_date_format = '%Y-%m-%d %H:%M:%S'
|
||||
_path_prefix = ""
|
||||
_hostname_suffix = ".binaprojects.com"
|
||||
|
||||
def get_download_url(self, store_id: int, category: SupermarketChain.XMLFilesCategory, session: requests.Session) \
|
||||
def get_download_url_or_path(self, store_id: int, category: SupermarketChain.XMLFilesCategory, session: requests.Session) \
|
||||
-> str:
|
||||
if not SupermarketChain.is_valid_store_id(store_id):
|
||||
raise ValueError(f"Invalid {store_id=} (store id must be a natural number)")
|
||||
hostname = f"http://{self.hostname_prefix}{self.hostname_suffix}"
|
||||
url = '/'.join([hostname, self.path_prefix, "MainIO_Hok.aspx"])
|
||||
req_res: requests.Response = session.get(url)
|
||||
@@ -27,7 +29,7 @@ class BinaProjectWebClient:
|
||||
if not any(filter_func(cur_json[FNAME_KEY]) for cur_json in jsons_files):
|
||||
return "" # Could not find non-full Promos/Prices file
|
||||
else:
|
||||
filter_func = lambda fname: f'-{store_id:03d}-20' in fname and category.name.replace('s', '') in fname
|
||||
filter_func = lambda fname: f'-{store_id:03d}-20' in fname and category.name.replace('s', '') in fname and 'null' not in fname
|
||||
suffix = next(
|
||||
cur_json[FNAME_KEY] for cur_json in jsons_files if filter_func(cur_json[FNAME_KEY]))
|
||||
down_url: str = '/'.join([hostname, self.path_prefix, "Download", suffix])
|
||||
|
Reference in New Issue
Block a user