-
Notifications
You must be signed in to change notification settings - Fork 0
/
basanti.py
191 lines (150 loc) · 5.04 KB
/
basanti.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import datetime
#change code so that all classes except the ones with lists inherit from the template class.
#No need to initialize the properties, just keep it an empty dictionary
#Make methods to add properties using the inherited funcitions
class TemplateClass:
def __init__(self) -> None:
self.properties = {
# "createdBy": created_by,
# "createdFor": created_for,
# "content": content,
# "createdAt": t,
# for mongo, it returns id automatically which will be used to set the id. To be changed when database is shifted
# the id returned by mongo will be added as an id field
}
def addID(self, id):
self.id = (
id # made to add id to object after pushing to mongo and recieving its id
)
def updateProperty(self, propDict: dict):
self.properties.update(propDict)
# for key, value in propDict.items():
# self.properties[key] = value
def deleteProperty(self, key):
self.properties.pop(key)
def getProperty(self, key):
return self.properties[key]
class task(TemplateClass):
def __init__(self) -> None:
super().__init__()
class message(TemplateClass):
def __init__(
self
# created_by: person,
# created_for: list[person],
# content: str,
# t: datetime.datetime,
) -> None:
super().__init__()
class events(TemplateClass):
def __init__(self) -> None:
super().__init__()
# name of event stored in content
# make this better by changing update property to take in a dictionary
class person(TemplateClass):
def __init__(self) -> None:
super().__init__()
#name
#year
#phone
#chat id
class inv_object(TemplateClass):
def __init__() -> None:
super().__init__()
#name
#quantity
#location
class Messages:
def __init__(self) -> None:
self.all_messages: list[message] = []
def add_message(self, msg):
self.all_messages.append(msg)
def remove_message(self, id):
for el in self.all_messages:
if el.id == id:
self.all_messages.remove(el)
def get_message_person(self, person: person):
return [
msg
for msg in self.all_messages
if person.properties["name"] in msg.properties["createdFor"]
]
class People:
def __init__(self, p: list[person] = []) -> None:
self.all_persons = p
def add_person(self, person):
self.all_persons.append(person)
def remove_person_by_id(self, id):
for el in self.all_persons:
if el.id == id:
self.all_persons.remove(el)
def remove_person_by_prop(self, prop, val):
for el in self.all_persons:
if el.properties[prop] == val:
self.all_persons.remove(el)
def get_person_by_prop(self, prop, val):
for el in self.all_persons:
if el.properties[prop] == val:
return el
"""
People Object in mongo looks like:
P = {
'_id': {'$oid': 'id_value'}, 'properties': {all properties}
}
"""
class Schedules:
def __init__(self, e:list[events]=[]) -> None:
self.all_events = e
def add_event(self, e):
self.all_events.append(e)
def remove_event_by_id(self, id):
for el in self.all_events:
if el.id == id:
self.all_events.remove(el)
def remove_event_by_name(self, name):
for el in self.all_events:
if el.properties["content"] == name:
self.all_events.remove(el)
def get_event_by_name(self, name):
for el in self.all_events:
if el.properties["content"] == name:
return el
def get_event_by_id(self, id):
for el in self.all_events:
if el.id == id:
return el
def update_event_by_id(self, id, new):
for i, el in enumerate(self.all_events):
if el.id == id:
self.all_events[i] = new
class Tasks:
def __init__(self, t=[]) -> None:
self.all_tasks = t
def add_task(self, t):
self.all_tasks.append(t)
def remove_task_by_id(self, id):
for el in self.all_tasks:
if el.id == id:
self.all_tasks.remove(el)
def get_task_by_id(self, id):
for el in self.all_tasks:
if el.id == id:
return el
def update_event_by_id(self, id, new):
for i, el in enumerate(self.all_events):
if el.id == id:
self.all_events[i] = new
return
class Inventory:
def __init__(self, i=[]) -> None:
self.inv_list = i
def add_item(self, item):
self.inv_list.append(item)
def remove_item(self, id):
for el in self.inv_list:
if el.id == id:
self.inv_list.remove(el)
def get_item(self, id):
for el in self.inv_list:
if el.id == id:
return el