-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinventory_add.py
executable file
·60 lines (51 loc) · 1.68 KB
/
inventory_add.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
#!/usr/bin/env python
import pickle
import sys
from xmlrpclib import ServerProxy, Error
import datetime
import urllib2
import simplejson
import inventory_grabcronometer
DEFAULT_EXPIRY_TIME = 600
#The default expiry time for items, in days.
def main():
try:
with open('inventory.inv', 'r') as filename:
inventoryarr = pickle.load(filename)
filename.close()
except IOError:
inventoryarr = {}
while True:
linetmp = sys.stdin.readline()
if not linetmp:
break
line = linetmp.rstrip()
#upc = line[7:]
upc = line
itemdata = datetime.date.today()
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."
specified_expiry_time = int(arr[0])
if specified_expiry_time < 600 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. Searching UPC Database."
print "UPC " + upc + " was not found in Cronometer. Please enter it."
continue
print "Successfully entered upc " + upc
print "Your current inventory contains:"
print inventoryarr
file = open('inventory.inv', 'w')
pickle.dump(inventoryarr,file)
file.close()
if __name__ == "__main__":
main()