-
Notifications
You must be signed in to change notification settings - Fork 10
/
inventory_remove.py
executable file
·47 lines (37 loc) · 1.14 KB
/
inventory_remove.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
#!/usr/bin/python
import pickle
import sys
import datetime
def main():
file = open('inventory.inv', 'r')
inventoryarr = pickle.load(file)
file.close()
shoppinglistfile = open('shoppinglist.txt', 'a')
while True:
print "Scan the UPC of the item you'd like to remove."
linetmp = sys.stdin.readline()
if not linetmp:
break
line = linetmp.rstrip()
#upc = line[7:]
upc = line
try:
tmp = inventoryarr[upc]
except:
print "The item " + upc + " does not yet exist in this database."
continue
try:
print upc + ": \"" + inventoryarr[upc][0][1] + "\", added on " + inventoryarr[upc].pop(1).strftime("%A, %d %B %Y") + " was successfully deleted."
shoppinglistfile.write(inventoryarr[upc][0][1] + ", " + upc + "\n")
except:
print "The item exists, but you currently have zero stock. Removing record from inventory entirely."
#inventoryarr[upc].pop(0)
inventoryarr.pop(upc,None)
shoppinglistfile.close()
print "Remaining items:"
print inventoryarr
file = open('inventory.inv', 'w')
pickle.dump(inventoryarr,file)
file.close()
if __name__ == "__main__":
main()