This repository was archived by the owner on Jul 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeliveryCalc.py
More file actions
165 lines (111 loc) · 4.1 KB
/
DeliveryCalc.py
File metadata and controls
165 lines (111 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python
# coding: utf-8
# In[1]:
def getMenu():
options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
driver.implicitly_wait(10)
url = input("Введите ссылку ресторана в формате [*delivery-club.ru/srv/*]: ")
print("Загрузка...\n")
driver.get(url)
menu = driver.find_elements_by_class_name('menu-product')
mealCost = {}
for meal in menu:
title = meal.find_element_by_class_name('menu-product__title').text
price = meal.find_element_by_class_name('menu-product__price').text
mealCost[title] = int(price[:-1]);
driver.close()
return mealCost
# In[57]:
def printOrder():
if len(order) == 0: return
totalForAll = 0
for name in order:
summary = 0
print(name,"{")
for meal in order[name]:
cnt = order[name][meal]
summary += mealCost[meal] * cnt
if cnt == 1: print(' {}: {}'.format(meal, mealCost[meal]))
else: print(' {}: {} x {} = {}'.format(meal,mealCost[meal],cnt, mealCost[meal]*cnt))
total = summary * (100 - sale) / 100 + delivery / len(order)
totalForAll += total
print('}','Итого: {} - {}% + {} / {} = {}'.format(summary,sale,delivery,len(order), total))
print('\n')
print("Сумма общего заказа: {}".format(totalForAll))
# In[39]:
def parseMeal(comm):
meal = ""
for i in range(2,len(comm)):
if i != 2: meal += " "
meal += comm[i]
return meal
def clear():
if name == 'nt': # win
_ = system('cls')
else: #mac and linux
_ = system('clear')
# In[2]:
from os import system, name
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
print("1. ПОЛУЧЕНИЕ МЕНЮ")
mealCost = getMenu()
# In[58]:
bill = {}
order = {}
delivery = 0
sale = 0
comm = ["Меню"]
output = ""
while(1):
clear()
print("2. СОСТАВЛЕНИЕ ЗАКАЗА")
if comm == ['Помощь']:
print('+ [имя] [блюдо]')
print('- [имя] [блюдо]')
print('Доставка [стоимость]')
print('Скидка [процент]')
print('Меню')
print('Завершить')
elif comm[0] == '+' and len(comm) >= 3:
meal = parseMeal(comm)
if mealCost.get(meal) == None:
output = "Неверное название блюда"
else:
if order.get(comm[1]) == None: order[comm[1]] = {}
if order[comm[1]].get(meal) == None: order[comm[1]][meal] = 0
order[comm[1]][meal] += 1;
elif comm[0] == '-' and len(comm) >= 3:
meal = parseMeal(comm)
if order.get(comm[1]) == None:
output = "Неверное имя"
elif order[comm[1]].get(meal) == None:
output = "Неверное название блюда"
else:
order[comm[1]][meal] -= 1
if order[comm[1]][meal] == 0: order[comm[1]].pop(meal)
if len(order[comm[1]]) == 0: order.pop(comm[1])
elif comm == ['Меню']:
for meal in mealCost:
print(meal,"-",mealCost[meal])
elif comm[0] == 'Доставка' and len(comm) == 2:
delivery = int(comm[1])
elif comm[0] == 'Скидка' and len(comm) == 2:
sale = int(comm[1])
elif comm == ['Завершить']:
break
else:
output = 'Неверная команда. Используйте [Помощь] для списка всех команд'
print("\n")
printOrder()
if(output != ""):
print("Ошибка:",output)
output = ""
comm = input("Введите команду: ")
comm = comm.split()
clear()
print("3. ИТОГ\n")
printOrder()
# In[ ]: