-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtaxcom_parser.py
34 lines (27 loc) · 1.01 KB
/
taxcom_parser.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
import requests
from currency import Currency
def get_items(qr_data):
url = "https://receipt.taxcom.ru/v01/show?" + qr_data[qr_data.find('&') + 1:]
request = requests.get(url)
if request.status_code == 404:
print("Can't connect with taxcom")
return []
content = request.content.decode("utf-8")
if "Чек по указанным параметрам не найден" in content:
return []
items = []
lines = content.split('\n')
i = 0
def __get_number(string):
return string[55:string[55:].find("/") + 54]
while i < len(lines):
if lines[i].strip() == """<span class="value receipt-value-1030">""":
name = lines[i + 1].strip()
quantity = __get_number(lines[i + 10])
price = __get_number(lines[i + 12])
cost = __get_number(lines[i + 15])
items.append([name + ': ' + quantity + " * " + price + " = ", Currency(cost)])
i += 49
else:
i += 1
return items