Skip to content

Commit 3d0e554

Browse files
committed
WIP
1 parent 5283df1 commit 3d0e554

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

grocery-shopping/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.data

grocery-shopping/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Grocery shopping
1+
# Grocery shopping[WIP]
22

33
You enter with items to be store in a `.data` file
44

grocery-shopping/grocery-list.data

-50 Bytes
Binary file not shown.

grocery-shopping/grocery_list_repository.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pickle
2+
import grocery_list
23

34
file_name = "grocery-list.data"
45

@@ -15,6 +16,16 @@ def read():
1516
return items
1617

1718

18-
def update(items):
19+
def update(item, new_item):
20+
items = read()
21+
items[items.index(item)] = new_item
1922
with open(file_name, "r+b") as f:
2023
pickle.dump(items, f)
24+
25+
26+
def delete(item):
27+
items = read()
28+
items.remove(item)
29+
with open(file_name, "r+b") as f:
30+
items = grocery_list.get_list()
31+
pickle.dump(items, f)

grocery-shopping/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
def main():
66
option = 0
7+
items = grocery_list_repository.read()
78
while True:
89
print("1 - Add item to the list")
910
print("2 - Update item from the list")
@@ -19,10 +20,10 @@ def main():
1920
elif option == 2:
2021
item = input("Enter the item you want to replace: ")
2122
new_item = input("Enter the new item to store on the list: ")
22-
grocery_list.alter(item, new_item)
23+
grocery_list_repository.update(item, new_item)
2324
elif option == 3:
2425
item = input("Enter the item you want to remove: ")
25-
grocery_list.exclude(item)
26+
grocery_list_repository.delete(item)
2627
elif option == 4:
2728
print("Items - ")
2829
print(grocery_list_repository.read())

0 commit comments

Comments
 (0)