has added binaproject clients

This commit is contained in:
KorenLazar
2021-02-07 10:46:54 +02:00
parent 9983d07c2b
commit 850d3963fe
11 changed files with 70 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
# Supermarket basic scraping
The library supports scraping from Shufersal, CoOp and Zol Vebegadol.
The library supports scraping from Shufersal, CoOp, Rami Levi, Osher Ad, Zol Vebegadol, Tiv Taam, Freshmarket, Mahsanei Hashook, Victory, Maayan2000, Yohananof, Stop Market, Keshet Taamim, Hazi Hinam, Dor Alon supermarkets, Shefa Birkat Hashem, Shuk Hayir, King Store and Super Bareket.
## Installation
clone:

View File

@@ -0,0 +1,35 @@
import json
import requests
from supermarket_chain import SupermarketChain
class BinaProjectWebClient:
_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) \
-> str:
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)
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([hostname, self.path_prefix, "Download", suffix])
print(down_url)
return down_url
@property
def hostname_prefix(self):
return repr(type(self))
@property
def path_prefix(self):
return type(self)._path_prefix
@property
def hostname_suffix(self):
return type(self)._hostname_suffix

View File

@@ -1,6 +1,4 @@
import json
from abc import abstractmethod
import requests
from supermarket_chain import SupermarketChain

7
chains/king_store.py Normal file
View File

@@ -0,0 +1,7 @@
from chains.binaproject_web_client import BinaProjectWebClient
from supermarket_chain import SupermarketChain
class KingStore(BinaProjectWebClient, SupermarketChain):
_path_prefix = "Food_Law"
_hostname_suffix = ".co.il"

6
chains/maayan2000.py Normal file
View File

@@ -0,0 +1,6 @@
from chains.binaproject_web_client import BinaProjectWebClient
from supermarket_chain import SupermarketChain
class Maayan2000(BinaProjectWebClient, SupermarketChain):
pass

View File

@@ -0,0 +1,6 @@
from chains.binaproject_web_client import BinaProjectWebClient
from supermarket_chain import SupermarketChain
class ShefaBirkatHashem(BinaProjectWebClient, SupermarketChain):
pass

7
chains/shuk_hayir.py Normal file
View File

@@ -0,0 +1,7 @@
from chains.binaproject_web_client import BinaProjectWebClient
from supermarket_chain import SupermarketChain
class ShukHayir(BinaProjectWebClient, SupermarketChain):
@property
def hostname_prefix(self): return "shuk-hayir"

View File

@@ -4,7 +4,6 @@ from supermarket_chain import SupermarketChain
class StopMarket(CerberusWebClient, SupermarketChain):
_date_hour_format = '%Y-%m-%d %H:%M:%S'
@property
def username(self):
return 'Stop_Market'

View File

@@ -3,4 +3,4 @@ from supermarket_chain import SupermarketChain
class TivTaam(CerberusWebClient, SupermarketChain):
_class_name = 'TivTaam'
pass

View File

@@ -1,26 +1,6 @@
import json
import requests
from chains.binaproject_web_client import BinaProjectWebClient
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
class ZolVebegadol(BinaProjectWebClient, SupermarketChain):
pass

View File

@@ -22,6 +22,10 @@ from chains import (
zol_vebegadol,
rami_levi,
osher_ad,
maayan2000,
shuk_hayir,
king_store,
shefa_birkat_hashem,
)
# TODO: fix problem of left-to-right printing