minor changes

This commit is contained in:
KorenLazar
2021-02-06 22:53:18 +02:00
parent 18f3fa32b9
commit 67bff9fa76
20 changed files with 44 additions and 46 deletions

5
chains/bareket.py Normal file
View File

@@ -0,0 +1,5 @@
from chains.mahsaneiHashook import MahsaneiHashook
class Bareket(MahsaneiHashook):
pass

View File

@@ -0,0 +1,31 @@
import json
from abc import abstractmethod
import requests
from supermarket_chain import SupermarketChain
class CerberusWebClient:
def get_download_url(self, store_id: int, category: SupermarketChain.XMLFilesCategory, session: requests.Session) \
-> str:
hostname: str = "https://publishedprices.co.il"
# Post the payload to the site to log in
session.post(hostname + "/login/user", data={'username': self.username})
# Scrape the data
ajax_dir_payload: dict = {'iDisplayLength': 100000, 'sSearch': category.name.replace('s', '')}
s: requests.Response = session.post(hostname + "/file/ajax_dir", data=ajax_dir_payload)
s_json: dict = json.loads(s.text)
suffix: str = next(d['name'] for d in s_json['aaData'] if f'-{store_id:03d}-20' in d['name'])
download_url: str = hostname + "/file/d/" + suffix
print(download_url)
return download_url
@property
@abstractmethod
def username(self):
pass

5
chains/co_op.py Normal file
View File

@@ -0,0 +1,5 @@
from chains.mahsaneiHashook import MahsaneiHashook
class CoOp(MahsaneiHashook):
pass

11
chains/dor_alon.py Normal file
View File

@@ -0,0 +1,11 @@
from chains.cerberus_web_client import CerberusWebClient
from supermarket_chain import SupermarketChain
class DorAlon(CerberusWebClient, SupermarketChain):
_date_hour_format = '%Y-%m-%d %H:%M:%S'
_class_name = 'DorAlon'
@property
def username(self):
return self._class_name

11
chains/freshmarket.py Normal file
View File

@@ -0,0 +1,11 @@
from chains.cerberus_web_client import CerberusWebClient
from supermarket_chain import SupermarketChain
class Freshmarket(CerberusWebClient, SupermarketChain):
_date_hour_format = '%Y-%m-%d %H:%M:%S'
_class_name = 'Freshmarket'
@property
def username(self):
return self._class_name

11
chains/hazi_hinam.py Normal file
View File

@@ -0,0 +1,11 @@
from chains.cerberus_web_client import CerberusWebClient
from supermarket_chain import SupermarketChain
class HaziHinam(CerberusWebClient, SupermarketChain):
_date_hour_format = '%Y-%m-%d %H:%M:%S'
_class_name = 'HaziHinam'
@property
def username(self):
return self._class_name

11
chains/keshet.py Normal file
View File

@@ -0,0 +1,11 @@
from chains.cerberus_web_client import CerberusWebClient
from supermarket_chain import SupermarketChain
class Keshet(CerberusWebClient, SupermarketChain):
_date_hour_format = '%Y-%m-%d %H:%M:%S'
_class_name = 'Keshet'
@property
def username(self):
return self._class_name

33
chains/mahsaneiHashook.py Normal file
View File

@@ -0,0 +1,33 @@
from typing import Dict, List
import requests
from bs4 import BeautifulSoup
from bs4.element import Tag
from item import Item
from supermarket_chain import SupermarketChain
class MahsaneiHashook(SupermarketChain):
_promotion_tag_name = 'Sale'
_promotion_update_tag_name = 'PriceUpdateDate'
_date_format = '%Y/%m/%d'
_date_hour_format = '%Y/%m/%d %H:%M:%S'
_update_date_format = '%Y/%m/%d %H:%M:%S'
_item_tag_name = 'Product'
@staticmethod
def get_download_url(store_id: int, category: SupermarketChain.XMLFilesCategory, session: requests.Session) -> str:
prefix = "http://matrixcatalog.co.il/"
url = prefix + "NBCompetitionRegulations.aspx"
req_res: requests.Response = requests.get(url)
soup = BeautifulSoup(req_res.text, features='lxml')
suffix: str = soup.find('a', href=lambda value: value and category.name.replace('s', '') in value
and f'-{store_id:03d}-20' in value).attrs['href']
down_url: str = prefix + suffix
print(down_url)
return down_url
@staticmethod
def get_items(promo: Tag, items_dict: Dict[str, Item]) -> List[Item]:
promo_item = items_dict.get(promo.find('ItemCode').text)
return [promo_item] if promo_item else []

12
chains/osher_ad.py Normal file
View File

@@ -0,0 +1,12 @@
from chains.cerberus_web_client import CerberusWebClient
from supermarket_chain import SupermarketChain
class OsherAd(CerberusWebClient, SupermarketChain):
_date_hour_format = '%Y-%m-%d %H:%M:%S'
_class_name = 'OsherAd'
@property
def username(self):
return self._class_name

11
chains/rami_levi.py Normal file
View File

@@ -0,0 +1,11 @@
from chains.cerberus_web_client import CerberusWebClient
from supermarket_chain import SupermarketChain
class RamiLevi(CerberusWebClient, SupermarketChain):
_date_hour_format = '%Y-%m-%d %H:%M:%S'
_class_name = 'RamiLevi'
@property
def username(self):
return self._class_name

18
chains/shufersal.py Normal file
View File

@@ -0,0 +1,18 @@
import requests
from bs4 import BeautifulSoup
from supermarket_chain import SupermarketChain
class ShuferSal(SupermarketChain):
@staticmethod
def get_download_url(store_id: int, category: SupermarketChain.XMLFilesCategory, session: requests.Session) -> str:
url = f"http://prices.shufersal.co.il/FileObject/UpdateCategory?catID={category.value}"
if SupermarketChain.is_valid_store_id(int(store_id)):
url += f"&storeId={store_id}"
req_res: requests.Response = requests.get(url)
soup: BeautifulSoup = BeautifulSoup(req_res.text, features='lxml')
down_url: str = soup.find('a', text="לחץ להורדה")['href']
print(down_url)
return down_url

11
chains/stop_market.py Normal file
View File

@@ -0,0 +1,11 @@
from chains.cerberus_web_client import CerberusWebClient
from supermarket_chain import SupermarketChain
class StopMarket(CerberusWebClient, SupermarketChain):
_date_hour_format = '%Y-%m-%d %H:%M:%S'
_class_name = 'Stop_Market'
@property
def username(self):
return self._class_name

10
chains/tiv_taam.py Normal file
View File

@@ -0,0 +1,10 @@
from chains.cerberus_web_client import CerberusWebClient
from supermarket_chain import SupermarketChain
class TivTaam(CerberusWebClient, SupermarketChain):
_class_name = 'TivTaam'
@property
def username(self):
return self._class_name

5
chains/victory.py Normal file
View File

@@ -0,0 +1,5 @@
from chains.mahsaneiHashook import MahsaneiHashook
class Victory(MahsaneiHashook):
pass

11
chains/yohananof.py Normal file
View File

@@ -0,0 +1,11 @@
from chains.cerberus_web_client import CerberusWebClient
from supermarket_chain import SupermarketChain
class Yohananof(CerberusWebClient, SupermarketChain):
_date_hour_format = '%Y-%m-%d %H:%M:%S'
_class_name = 'Yohananof'
@property
def username(self):
return self._class_name

26
chains/zol_vebegadol.py Normal file
View File

@@ -0,0 +1,26 @@
import json
import requests
from supermarket_chain import SupermarketChain
class ZolVebegadol(SupermarketChain):
_date_hour_format = '%Y-%m-%d %H:%M:%S'
_update_date_format = '%Y-%m-%d %H:%M:%S'
item_tag_name = 'Item'
@property
def update_date_format(self):
return ZolVebegadol.date_hour_format
@staticmethod
def get_download_url(store_id: int, category: SupermarketChain.XMLFilesCategory, session: requests.Session) -> str:
prefix = "http://zolvebegadol.binaprojects.com"
url = prefix + "/MainIO_Hok.aspx"
req_res: requests.Response = session.get(url)
jsons_files = json.loads(req_res.text)
suffix = next(cur_json["FileNm"] for cur_json in jsons_files if f'-{store_id:03d}-20' in cur_json["FileNm"]
and category.name.replace('s', '') in cur_json["FileNm"])
down_url: str = '/'.join([prefix, "Download", suffix])
print(down_url)
return down_url