-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
80 lines (66 loc) · 2.43 KB
/
test.py
File metadata and controls
80 lines (66 loc) · 2.43 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
import sys
import time
import colruyt
import display
import socket
import fcntl
import struct
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
if len(sys.argv) != 3:
exit(0)
username = sys.argv[1]
password = sys.argv[2]
api = colruyt.ColruytAPI(username, password)
display = display.Display()
ip = get_ip_address("eth0")
while True:
try:
display.show_message("your ip is %s" % (ip))
barcode = sys.stdin.readline()
barcode = barcode.strip()
try:
response = api.search(barcode)
print "zoeken van product met barcode %s: %s" % (barcode, response["status"]["meaning"])
productId = response["data"]["searchResults"][0]["list"][0]["id"]
productBrand = response["data"]["searchResults"][0]["list"][0]["brand"]
productDescription = response["data"]["searchResults"][0]["list"][0]["description"]
productImagePath = response["data"]["searchResults"][0]["list"][0]["overviewImage"]
price = response["data"]["searchResults"][0]["list"][0]["price"]
image = api.get_product_image(productImagePath)
if image is not None:
display.show_product(image, productBrand, productDescription, price)
print "Product [%s] %s - %s : %s euro" % (productId, productBrand, productDescription, price)
response = api.add(productId, 1, "S")
print "toevoegen aan de winkelmand: %s" % (response["status"]["meaning"])
time.sleep(5)
basket = api.show_basket()
basket_content = u""
for category in basket["data"]["articles"]:
basket_content += category["colruyt.cogomw.bo.RestTreeBranch"]["description"] + "\n"
for article in category["list"]:
basket_content += " %s - %s : %s stuks\n" % (article["brand"], article["description"], article["quantity"])
basket_content += u"----------------------\n"
basket_content += u"subtotal: %s euro\n" % (basket["data"]["subTotal"])
basket_content += u"service cost: %s euro\n" % (basket["data"]["serviceCost"])
basket_content += u"total: %s euro\n" % (basket["data"]["total"])
basket_content += u"-----------------------\n"
display.show_message(basket_content)
print basket_content
time.sleep(5)
except ValueError as e:
print "something went wrong: %s" % (e)
except:
break
except (KeyboardInterrupt, SystemExit):
print "catched keyboardinterrupt"
break
display.close()
api.logout()
del(display)
del(api)