-
Notifications
You must be signed in to change notification settings - Fork 1
/
check.py
129 lines (115 loc) · 3.37 KB
/
check.py
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
import re
short_names_to_normal_prices = {
"cg": 70,
"cgv": 90,
"cgc": 90,
"c": 30,
"cd": 60,
"ca": 70,
"cl": 65,
"a": 65,
"m": 70,
"cc": 70,
"ch": 60,
"cr": 60,
"mf": 60,
"gfingsoif": 160,
"chocochoco": 140,
"lebonmatin": 115,
"mac": 100,
"bp": 60,
"bb": 240,
"tg": 20,
"cs": 20,
"cgn": 90,
"mo": 60,
"ra": 35,
"tenten_old": 1000
}
short_names_to_delivery_prices = {
"cg": 80,
"cgv": 100,
"cgc": 100,
"c": 40,
"cd": 70,
"ca": 80,
"cl": 75,
"a": 75,
"m": 80,
"cc": 80,
"ch": 65,
"cr": 65,
"mf": 65,
"gfingsoif": 180,
"chocochoco": 160,
"lebonmatin": 135,
"mac": 110,
"bp": 70,
"bb": 280,
"tg": 30,
"cs": 30,
"cgn": 100,
"mo": 65,
"ra": 50
}
shorts_names_to_public_services_prices = {
"c": 20,
"cr": 15,
"cg": 30,
"ch": 25
}
async def check_price(displayed_price: int, s: str, ignore_price: bool = False):
delivery = False
discount = False
public_service = False
tenten_old = False
total = 0
prime = 0
brackets_options = re.findall(r'\[(.*?)\]', s)
if brackets_options is not None:
for option in brackets_options:
if option == "Livraison":
delivery = True
elif option == "Réduction 10%":
discount = True
elif option == "Service Public":
public_service = True
elif option == "10-10":
tenten_old = True
try:
tip = 0
if "(" in s:
tip = re.search(r".*?\((.*?)\)", s).group(1)
tip = tip.replace("$", "").replace(" pb", "")
if discount is True or delivery is True or public_service is True:
s = s.split("]")[2 if discount is True and delivery is True else 1]
regex = r"(.*?){}".format(r"\(" if tip != 0 else "")
content = re.search(regex, s).group(1) if regex != "(.*?)" else s
split = re.split(r"([0-9]+)([a-z]+)", content.lower().replace(" ", ""))
for i in range(0, len(split)):
item = split[i]
if item != "" and item.isnumeric() is False:
amount = int(split[i - 1])
if delivery is True:
total_price = amount * int(short_names_to_delivery_prices.get(item))
elif public_service is True:
total_price = amount * int(shorts_names_to_public_services_prices.get(item))
else:
total_price = amount * int(short_names_to_normal_prices.get(item))
total += total_price
prime += 25 * amount if item != "tenten" else 250 * amount
if not ignore_price:
if tenten_old is True and int(displayed_price) == 900:
return {"value": True, "prime": prime}
if int(displayed_price) == (
int(total + int(tip)) if discount is False else int(int(total * 0.9) + int(tip))):
if tip != 0:
prime += int(int(tip) * 0.75)
return {"value": True, "prime": prime}
else:
return {"value": False, "prime": 0}
else:
return {"value": True, "prime": prime}
except:
print("Found a bill with invalid declaration, skipping...")
return {"value": False, "prime": 0}