-
Notifications
You must be signed in to change notification settings - Fork 10
/
inventory_addname.py
executable file
·54 lines (45 loc) · 1.19 KB
/
inventory_addname.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
#!/usr/bin/python
import pickle
import sys
def grabessentials():
itemname = ''
expiry = ''
print "Please enter the descriptive name for this item:"
length = sys.stdin.readline()
if length:
itemname = length
else:
print "You didn't enter a valid name. Try again."
return([])
print "Please enter the approximate amount of shelf-life for this item (in days):"
length = sys.stdin.readline()
if length:
expiry = int(length)
else:
print "You didn't enter a valid shelf-life. Enter the item again."
return([])
return([expiry,itemname])
def main():
file = open('inventory.inv', 'r')
inventoryarr = pickle.load(file)
file.close()
while True:
print "Enter the EAN code of an item you wish to modify."
linetmp = sys.stdin.readline()
if not linetmp:
break
#line = linetmp.rstrip()[7:]
upc = linetmp.rstrip()
arr = grabessentials()
try:
tmp = inventoryarr[upc]
print "The item is already in the database. Unless you quit now I'll overwrite its name..."
inventoryarr[upc][0] = arr
except:
inventoryarr[upc] = [arr]
print "Added item " + upc + "."
file = open('inventory.inv', 'w')
pickle.dump(inventoryarr,file)
file.close()
if __name__ == "__main__":
main()