-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.py
53 lines (46 loc) · 1.76 KB
/
user.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
import csv
from os import path
import configuration as conf
from activity import Activity
class User:
def __init__(self, user_id, user_name, password):
self.user_name = user_name
self.password = password
self.user_id = user_id
self.activity_by_category = {}
def create_data_file(self):
file_name = conf.DATA_FILE.format(user_id=self.user_id)
if path.exists(file_name):
return
with open(file_name, 'w', newline='') as csvfile:
data_writer = csv.writer(csvfile)
data_writer.writerow(conf.DATA_FILE_COL)
def create_activity(self, category, name):
if category not in self.activity_by_category:
print(conf.E_CATEGORY_DOESNT_EXISTS)
return
if name in self.activity_by_category[category]:
print(conf.E_ACTIVITY_EXISTS)
return
self.activity_by_category[category].append(name)
return Activity(self.user_id, category, name)
def create_category(self, name):
if name in self.activity_by_category:
print(conf.E_CATEGORY_EXISTS)
return
self.activity_by_category[name] = []
def delete_activity(self, category, name):
if category not in self.activity_by_category:
print(conf.E_CATEGORY_DOESNT_EXISTS)
return False
if name not in self.activity_by_category[category]:
print(conf.E_ACTIVITY_DOESNT_EXISTS)
return False
self.activity_by_category[category].remove(name)
return True
def delete_category(self, name):
if name not in self.activity_by_category:
print(conf.E_CATEGORY_DOESNT_EXISTS)
return False
self.activity_by_category.pop(name)
return True