-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
79 lines (62 loc) · 1.66 KB
/
main.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
import xlrd
import mraa
import csv
import datakick
import re
import os
#Reads the xls files and returns it as an object
#Setting up the touch button
touch = mraa.Gpio(29)
touch.dir(mraa.DIR_IN)
isTouched = int(touch.read())
if(isTouched):
reset = open('/var/www/html/barcodes.csv','w')
reset.write('')
reset.close()
itemList = []
with open('/var/www/html/barcodes.csv', 'r') as f:
reader = csv.reader(f)
barcodeList = list(reader) #contains every barcode in .csv
for row in barcodeList:
for col in row:
if col == '':
break
barcode = col
product = datakick.find_product(barcode)
itemList.append(product)
print(barcodeList)
def getCRV(item):
if "oz" in item.size:
if int(re.sub("[^0-9]", "", item.size[0:2])) < 24:
return 0.05
else:
return 0.1
else:
return 0
def getCarbonFootprint(item):
return 82.8
def getTotalCRV(itemList):
totalCRV = 0
for item in itemList:
totalCRV += getCRV(item)
return totalCRV
def getTotalCarbonFootprint(itemList):
carbonFootprint = 0
for item in itemList:
carbonFootprint += getCarbonFootprint(item)
return carbonFootprint
print(getTotalCRV(itemList))
print(getTotalCarbonFootprint(itemList))
display = open('toLCD.txt','w')
'''
if (getCarbonFootprint(itemList) == 0):
display.write(str(0))
else:
display.write(str(format(getCarbon(total),'.2f'))+'\n')
if (getCRV(total) == 0):
display.write(str(0))
else:
display.write(str(format(getCRV(total),'.2f'))+'\n')
'''
display.write(str(format(getTotalCarbonFootprint(itemList),'.2f'))+'\n')
display.write(str(format(getTotalCRV(itemList),'.2f'))+'\n')