def visit(self): ser_dis_amount = self.all_service_price * Discount(self.type, "service").discount() final_ser_price = self.all_service_price - ser_dis_amount pro_dis_amount = self.all_product_price * Discount(self.type, "product").discount() final_pro_price = self.all_product_price - pro_dis_amount total = final_ser_price + final_pro_price return ser_dis_amount, pro_dis_amount, total, final_ser_price, final_pro_price
def discounts_mango(url, scroll_pages, threshold, sleep_time): browser = Chrome() browser.get(url) for i in range(scroll_pages): time.sleep(sleep_time) browser.find_element_by_tag_name('body').send_keys(Keys.END) soup = BeautifulSoup(browser.execute_script('return document.documentElement.outerHTML'), 'html.parser') main = soup.find('div', class_='main-vertical-body') pages = main.find_all('ul', class_='page--hidden') if len(pages) == 0: pages = main.find_all('div', class_='page') for page in pages: items = page.find_all('li') for item in items: divs = item.find_all('div') if 'outlet' in url: name = get_name_mango_outlet(divs) regular_price, discount_price = get_prices_mango_outlet(divs) else: name = get_name_mango(divs) get_prices_mango(divs) regular_price, discount_price = get_prices_mango(divs) discount_pct = get_discount_pct(discount_price, regular_price) if discount_pct > threshold: uri = URI_SCHEME_NETLOC.format(uri=(urlparse(url))) + item.a['href'] discounts.append(Discount(discount_pct, discount_price, name, uri)) browser.close()
def discounts_tezyo(url, threshold_pct, price_limit=10000, sleep=2): browser = Chrome() browser.get(url) try: condition = True while condition is True: soup = BeautifulSoup(browser.execute_script('return document.documentElement.outerHTML'), 'html.parser') items = soup.find_all('li', class_='item') for item in items: price_p = item.find('p', class_='old-price') if price_p is None: continue regular = parse_price(price_p.span.text) discount = parse_price(item.find('span', class_='discount-price').span.text) article = item.find('div', class_='product-info') if get_discount_pct(discount, regular) > threshold_pct and discount < price_limit: discounts.append((Discount(get_discount_pct(discount, regular), discount, article.h2.text, article.a['href']))) pages = browser.find_element(By.CSS_SELECTOR, 'div.pages') next_page = pages.find_elements(By.CSS_SELECTOR, 'li')[-1] if next_page.is_displayed(): next_page.click() time.sleep(sleep) last_btn = soup.find('div', class_='pages').find_all('li')[-1] if last_btn.find('a', class_='next') is None: condition = False except ElementClickInterceptedException as e: print(traceback.format_exc()) browser.close()
def discounts_hm(url, threshold_pct, sleep=1): browser = Chrome() browser.get(url) try: for x in range(100): more = browser.find_element(By.CSS_SELECTOR, 'button.js-load-more') if more.is_displayed(): more.click() browser.find_element_by_tag_name('body').send_keys(Keys.END) time.sleep(sleep) soup = BeautifulSoup(browser.execute_script('return document.documentElement.outerHTML'), 'html.parser') items = soup.find_all('li', class_='product-item') for item in items: prices = item.find('strong', class_='item-price') discount = parse_price(prices.find('span', class_='sale').text) regular = parse_price(prices.find('span', class_='regular').text) article = item.find('h3', class_='item-heading') uri = URI_SCHEME_NETLOC.format(uri=(urlparse(url))) + article.a['href'] if get_discount_pct(discount, regular) > threshold_pct: discounts.append(Discount(get_discount_pct(discount, regular), discount, article.a.text, uri)) except ElementClickInterceptedException as e: print(traceback.format_exc()) browser.close()
def discounts_reserved(url, threshold): soup = BeautifulSoup(requests.get(url).content, 'html.parser') articles = soup.find_all('article', class_='es-product') for article in articles: discount_price = parse_price(article.section.contents[0].text) regular_price = parse_price(article.section.contents[1].text) discount_pct = get_discount_pct(discount_price, regular_price) if discount_pct > threshold: name = article.figure.a.img['alt'] uri = article.figure.a['href'] discounts.append(Discount(discount_pct, discount_price, name, uri))
def test_all_attrs(self): attrs = [ 'code', 'count', 'start_date', 'end_date', 'percentage', 'minimum_order', 'maximum_order' ] self.assertTrue(hasattr(Discount, 'sample'), "sample method not implemented in Discount class") discount = Discount.sample() for attr in attrs: self.assertTrue( hasattr(discount, attr), 'discount objects has no attr called {}'.format(attr))
def deserialize_data(data: dict) -> dict: items = {} for item in data: validate(item, itemSchema) discount = Discount(int(item.get('discount').get('quantity')), float(item.get('discount').get( 'cost'))) if item.get('discount') else None items[item.get('id')] = Item(item.get('id'), item.get('name'), float(item.get('cost')), discount) return items
def discounts_zara(url, threshold): soup = BeautifulSoup(requests.get(url).content, 'html.parser') items = soup.find_all('li', class_='_product') for item in items: prices = item.find('div', class_='_product-price') if prices is not None: regular_price_span = prices.find('span', class_='main-price') if regular_price_span is None: regular_price_span = prices.find('span', class_='line-through') regular_price = parse_price(regular_price_span['data-price']) discount_price_span = prices.find('span', class_='sale') if discount_price_span is not None: discount_price = parse_price(discount_price_span['data-price']) discount_pct = get_discount_pct(discount_price, regular_price) if discount_pct > threshold: name_div = item.find('div', class_='product-info-item-name') name = name_div.a.text uri = name_div.a['href'] discounts.append(Discount(discount_pct, discount_price, name, uri))
product = "product" service = "service" # ---------------------Test of Customer Class Functions------------------------ print("///////////////////// Customer Function Test ///////////////////\n") user1.print_user() print("{}{}".format(user1.call(), '\n')) print("///////////////////////////////////////////////////////////////\n") print(100 * "*" + '\n') # ----------------------------------------------------------------------------- # ------------------------- Test Of Discount Class ---------------------------- print("/////////////////// Discount Functions Test ////////////////////\n") print("User1 Service Discount: " + str(Discount(user1.call()[1], service).discount())) print("User1 Product Discount: " + str(Discount(user1.call()[1], product).discount())) print("\n///////////////////////////////////////////////////////////////\n") print(100 * "*" + '\n') # ----------------------------------------------------------------------------- # ------------------Print All Users Data Info with discount-------------------- users = [user1, user2, user3, user4] print("//////////// All user Name, Type and Discount Info /////////////\n") for i in range(4): print( print_user_disc_info(users[i].call()[0], users[i].call()[1], Discount(users[i].call()[1], service).discount(), Discount(users[i].call()[1], product).discount()))
def setUp(self): self.beans = Item("Beans", 0.20) self.milk = Item("Milk", 0.75) self.basket = Basket() self.discount = Discount()
class TestItem(unittest.TestCase): def setUp(self): self.beans = Item("Beans", 0.20) self.milk = Item("Milk", 0.75) self.basket = Basket() self.discount = Discount() def test_bogof_list_starts_empty(self): self.assertEqual(0, len(self.discount.bogof_items)) def test_can_add_item_to_bogof_list(self): self.discount.add_to_bogof(self.beans) self.assertEqual(1, len(self.discount.bogof_items)) def test_bogof_2_beans_is_20_pence(self): self.basket.add(self.beans) self.basket.add(self.beans) bogof_discount = self.discount.bogof_for_item(self.basket, self.beans) self.assertEqual(0.20, bogof_discount) def test_bogof_1_beans_is_0_pence(self): self.basket.add(self.beans) bogof_discount = self.discount.bogof_for_item(self.basket, self.beans) self.assertEqual(0.0, bogof_discount) def test_bogof_3_beans_is_20_pence(self): self.basket.add(self.beans) self.basket.add(self.beans) self.basket.add(self.beans) bogof_discount = self.discount.bogof_for_item(self.basket, self.beans) self.assertEqual(0.20, bogof_discount) def test_bogof_4_beans_is_40_pence(self): self.basket.add(self.beans) self.basket.add(self.beans) self.basket.add(self.beans) self.basket.add(self.beans) bogof_discount = self.discount.bogof_for_item(self.basket, self.beans) self.assertEqual(0.40, bogof_discount) def test_bogof_discount_basket_95_pence(self): self.basket.add(self.beans) self.basket.add(self.beans) self.basket.add(self.milk) self.basket.add(self.milk) self.discount.add_to_bogof(self.beans) self.discount.add_to_bogof(self.milk) bogof_discount = self.discount.bogof_discount(self.basket) self.assertEqual(0.95, bogof_discount) def test_10_percent_discount_on_total_over_20_pounds(self): dvd = Item("DVD", 20.00) self.basket.add(self.beans) self.basket.add(self.beans) self.basket.add(dvd) basket_total = self.discount.extra_10_per_cent(self.basket) self.assertEqual(18.36, basket_total) def test_extra_2_per_cent_discount__cust_has_loyalty_card(self): customer = Customer("Jack") customer.has_loyalty_card = True dvd = Item("DVD", 20.00) self.basket.add(dvd) basket_total = self.discount.extra_2_percent_for_loyal_cust( self.basket, customer) self.assertEqual(19.60, basket_total) def test_extra_2_per_cent_discount__cust_does_not_have_loyalty_card(self): customer = Customer("Jack") dvd = Item("DVD", 20.00) self.basket.add(dvd) basket_total = self.discount.extra_2_percent_for_loyal_cust( self.basket, customer) self.assertEqual(20.00, basket_total)
from discount import Discount from util import getInput, drawLines from transaction import Transaction from customer import Customer from employee import Employee def start_transactions(): drawLines() print "Start Billing" drawLines() ans = getInput("Are you a current employee (Y/N)?") if ans == "Y": emp = Employee() cust_details = emp.getEmployeeDetails() else: cust = Customer() cust_details = cust.getCustomerDetails() Transaction(cust_details) print "Completed Billing" drawLines() ans = getInput("Do you want to do more transactions (Y/N)?") if ans == "Y": start_transactions() if __name__ == "__main__": Store() Discount() start_transactions() Store.showClosingCatalogue()