changed chains' members to be 'immutable static'

This commit is contained in:
KorenLazar
2021-02-06 15:57:05 +02:00
parent 3a57edf5af
commit 5aa4cd734d
6 changed files with 50 additions and 126 deletions

View File

@@ -1,66 +1,28 @@
import json
from typing import Dict, List
import requests
from bs4.element import Tag
from item import Item
from supermarket_chain import SupermarketChain
class RamiLevi(SupermarketChain):
@property
def promotion_tag_name(self):
return 'Promotion'
@property
def promotion_update_tag_name(self):
return 'PromotionUpdateDate'
@property
def date_format(self):
return '%Y-%m-%d'
@property
def date_hour_format(self):
return '%Y-%m-%d %H:%M:%S'
@property
def update_date_format(self):
return '%Y-%m-%d %H:%M'
@property
def item_tag_name(self):
return 'Item'
_date_hour_format = '%Y-%m-%d %H:%M:%S'
@staticmethod
def get_download_url(store_id: int, category: SupermarketChain.XMLFilesCategory, session: requests.Session) -> str:
hostname = "https://publishedprices.co.il"
hostname: str = "https://publishedprices.co.il"
# Post the payload to the site to log in
session.post(hostname + "/login/user", data={'username': 'ramilevi'})
# Scrape the data
ajax_dir_payload = {'iDisplayLength': 100000, 'sSearch': category.name.replace('s', '')}
s = session.post(hostname + "/file/ajax_dir", data=ajax_dir_payload)
s_json = json.loads(s.text)
suffix = next(d['name'] for d in s_json['aaData'] if f'-{store_id:03d}-20' in d['name'])
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 = hostname + "/file/d/" + suffix
download_url: str = hostname + "/file/d/" + suffix
print(download_url)
return download_url
@staticmethod
def get_items(promo: Tag, items_dict: Dict[str, Item]) -> List[Item]:
items = list()
for item in promo.find_all('Item'):
item_code = item.find('ItemCode').text
full_item_info = items_dict.get(item_code)
if full_item_info:
items.append(full_item_info)
return items
class XMLFilesCategory(SupermarketChain.XMLFilesCategory):
All, Promos, PromosFull, Prices, PricesFull, Stores = range(6)
def __repr__(self):
return 'RamiLevi'