-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsholis.py
64 lines (48 loc) · 1.75 KB
/
sholis.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
61
62
63
64
"""
Shopping list class for sholibo the shopping list bot.
therealpeterpython - [email protected]
2019
"""
from datetime import datetime
import json
class ShoppingList:
def __init__(self):
self._items = list()
self._times = list()
#self._chat_id = chat_id
def __str__(self):
out = list()
out.append(list(zip(self._items, self._times)))
#out.append(self._chat_id)
return str(out)
def empty(self):
return not self._items
def get_items(self):
return self._items
def get_times(self):
return self._times
#def get_chat_id(self):
# return self._chat_id
def add_item(self, item):
self._items.append(item)
self._times.append(datetime.now())
def add_items(self, items):
time = datetime.now()
self._items.extend(items)
self._times.extend([time for _ in range(len(items))])
def remove_items(self, pos):
self._items = [item for index,item in enumerate(self._items) if not index in pos]
self._times = [time for index,time in enumerate(self._times) if not index in pos]
def remove_all(self):
self._items = list()
self._times = list()
def pprint_basic(self):
pstr = ""
for n, item in enumerate(self._items):
pstr += "({}) {}\n".format(n, item)
return pstr
def pprint_full(self):
pstr = ""
for n, (item, date) in enumerate(zip(self._items, self._times)):
pstr += "({}) {} [{}])\n".format(n, item, date.strftime("%d-%m-%Y %H:%M"))
return pstr