|
1 |
| -import grocery_list |
2 | 1 | import grocery_list_repository
|
3 | 2 |
|
| 3 | +items = grocery_list_repository.read() |
| 4 | + |
| 5 | + |
| 6 | +def options(option): |
| 7 | + if option == 1: |
| 8 | + item = input("Enter the item: ") |
| 9 | + global items |
| 10 | + items.append(item) |
| 11 | + grocery_list_repository.persist(items) |
| 12 | + print(f"Item {item} saved in the list") |
| 13 | + return 0 |
| 14 | + elif option == 2: |
| 15 | + item = input("Enter the item you want to remove: ") |
| 16 | + items.remove(item) |
| 17 | + grocery_list_repository.persist(items) |
| 18 | + print(f"Item {item} removed from the list") |
| 19 | + return 0 |
| 20 | + elif option == 3: |
| 21 | + print("Items - ") |
| 22 | + if grocery_list_repository.read(): |
| 23 | + items = grocery_list_repository.read() |
| 24 | + for item in items: |
| 25 | + print(item, end=" ") |
| 26 | + print() |
| 27 | + else: |
| 28 | + print("Empty list") |
| 29 | + return 0 |
| 30 | + elif option == 0: |
| 31 | + return 1 |
| 32 | + |
4 | 33 |
|
5 | 34 | def main():
|
6 | 35 | option = 0
|
7 |
| - items = grocery_list_repository.read() |
8 | 36 | while True:
|
9 | 37 | print("1 - Add item to the list")
|
10 |
| - print("2 - Update item from the list") |
11 |
| - print("3 - Delete item from the list") |
12 |
| - print("4 - Get all items from the list") |
13 |
| - print("5 - Save list") |
| 38 | + print("2 - Delete item from the list") |
| 39 | + print("3 - Get all items from the list") |
14 | 40 | print("0 - Exit")
|
15 |
| - option = int(input("> ")) |
16 |
| - |
| 41 | + option = options(int(input("> "))) |
17 | 42 | if option == 1:
|
18 |
| - item = input("Enter the item: ") |
19 |
| - grocery_list.add(item.title()) |
20 |
| - elif option == 2: |
21 |
| - item = input("Enter the item you want to replace: ") |
22 |
| - new_item = input("Enter the new item to store on the list: ") |
23 |
| - grocery_list_repository.update(item, new_item) |
24 |
| - elif option == 3: |
25 |
| - item = input("Enter the item you want to remove: ") |
26 |
| - grocery_list_repository.delete(item) |
27 |
| - elif option == 4: |
28 |
| - print("Items - ") |
29 |
| - print(grocery_list_repository.read()) |
30 |
| - elif option == 5: |
31 |
| - grocery_list_repository.persist(grocery_list.get_list()) |
32 |
| - elif option == 0: |
33 | 43 | break
|
34 | 44 |
|
| 45 | + |
35 | 46 | if __name__ == '__main__':
|
36 | 47 | main()
|
0 commit comments