-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinventory_add_and_remove.py
More file actions
executable file
·107 lines (94 loc) · 4.12 KB
/
inventory_add_and_remove.py
File metadata and controls
executable file
·107 lines (94 loc) · 4.12 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
#!/usr/bin/env python
import pickle
import sys
from xmlrpclib import ServerProxy, Error
import datetime
import urllib2
import simplejson
import select
import inventory_grabcronometer
DEFAULT_EXPIRY_TIME = 100
INPUT_TIMEOUT = 100
#This will add an item if it is scanned once,
#and remove it if scanned twice consecutively.
def main():
try:
with open('inventory.inv', 'r') as filename:
inventoryarr = pickle.load(filename)
filename.close()
except IOError:
inventoryarr = {}
lineprev = ""
while True:
lastRun = False
if select.select([sys.stdin], [], [], INPUT_TIMEOUT)[0]:
linetmp = sys.stdin.readline()
if lineprev == "":
lineprev = linetmp
if select.select([sys.stdin], [], [], INPUT_TIMEOUT)[0]:
linetmp = sys.stdin.readline()
if linetmp == lineprev:
removeItem = True
else:
removeItem = False
else:
lineprev = linetmp
linetmp = ""
removeItem = False
lastRun = True
else:
if linetmp == lineprev:
removeItem = True
else:
removeItem = False
else:
lineprev = linetmp
linetmp = ""
removeItem = False
lastRun = True
line = lineprev.rstrip()
upc = line
itemdata = datetime.date.today()
if removeItem == False:
if inventoryarr.has_key(upc):
inventoryarr[upc].append(itemdata)
else:
print "UPC" + upc + " is a brand new item. Searching Cronometer..."
arr = inventory_grabcronometer.cronometer(upc)
if arr != 0:
print "Found in Cronometer! Item successfully entered."
#inventoryarr[upc] = [arr]
specified_expiry_time = int(arr[0])
if specified_expiry_time < 100 and specified_expiry_time > 0:
arr2 = [specified_expiry_time,arr[1],arr[2]]
else:
arr2 = [DEFAULT_EXPIRY_TIME,arr[1],arr[2]]
inventoryarr[upc] = [arr2]
inventoryarr[upc].append(itemdata)
continue
print "Not found in Cronometer. Please add there."
continue
else:
try:
tmp = inventoryarr[upc]
print "Item added on " + tmp.pop(1).strftime("%A, %d %B %Y") + " was successfully deleted."
except:
print "Item to be removed did not exist in the database."
linetmp = ""
print "Successfully entered upc " + upc
if lastRun = True:
print "Saving entries..."
file = open('inventory.inv', 'w')
pickle.dump(inventoryarr,file)
file.close()
lineprev = ""
linetmp = ""
else:
lineprev = linetmp
print "Your current inventory contains:"
print inventoryarr
file = open('inventory.inv', 'w')
pickle.dump(inventoryarr,file)
file.close()
if __name__ == "__main__":
main()