summaryrefslogtreecommitdiff
path: root/kronos/parser.py
diff options
context:
space:
mode:
Diffstat (limited to 'kronos/parser.py')
-rw-r--r--kronos/parser.py51
1 files changed, 46 insertions, 5 deletions
diff --git a/kronos/parser.py b/kronos/parser.py
index 5f79144..0c39b95 100644
--- a/kronos/parser.py
+++ b/kronos/parser.py
@@ -9,12 +9,53 @@ Activity Parser
9 9
10class Activity(object): 10class Activity(object):
11 11
12 activity = "my activity" 12 def __init__(self, activity, description=None, category=None):
13 description = "Some cool stuff!" 13 self.activity = activity
14 category = "Home" 14 self.description = description
15 self.category = category
16
17 def __repr__(self):
18 return "Activity({0!r}, description={1!r}, category={2!r})".format(
19 self.activity, self.description, self.category)
15 20
16 21
17class ActivityParser(object): 22class ActivityParser(object):
18 23
19 def parse(self, text): 24 def __init__(self, text):
20 return Activity() 25 self.text = text
26 self.tokens = text.split(' ')
27
28 def parse(self):
29 activity = Activity(self._parse_activity())
30 activity.description = self._parse_description()
31 activity.category = self._parse_category()
32
33 return activity
34
35 def _parse_activity(self):
36 return self.text.split(',')[0].split('@')[0]
37
38 def _parse_description(self):
39 text = self.text
40
41 if ',' in self.text:
42 text = text.split(',', 1)[1]
43
44 if '@' in text:
45 text = text.split('@', 1)[0]
46
47 if text == self.text:
48 return None
49
50 return text.strip()
51
52 def _parse_category(self):
53 text = self.text
54
55 if '@' in text:
56 text = text.split('@', 1)[1]
57
58 if text == self.text:
59 return None
60
61 return text