diff options
Diffstat (limited to 'kronos/parser.py')
-rw-r--r-- | kronos/parser.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/kronos/parser.py b/kronos/parser.py index b18b4f9..8d93391 100644 --- a/kronos/parser.py +++ b/kronos/parser.py | |||
@@ -13,19 +13,34 @@ class Activity(object): | |||
13 | self.activity = activity | 13 | self.activity = activity |
14 | self.description = description | 14 | self.description = description |
15 | self.category = category | 15 | self.category = category |
16 | self.tags = [] | ||
16 | 17 | ||
17 | 18 | ||
18 | def parse_activity(text): | 19 | def parse_activity(text): |
19 | description = None | 20 | description = None |
21 | tags = [] | ||
20 | if ',' in text: | 22 | if ',' in text: |
21 | text, description = text.split(',', 1) | 23 | text, description = text.split(',', 1) |
22 | description = description.strip() | 24 | description = description.strip() |
23 | 25 | ||
26 | tokens = description.split(' ') | ||
27 | tags = parse_tags(tokens) | ||
28 | description = strip_tags(tokens) | ||
29 | |||
24 | category = None | 30 | category = None |
25 | if '@' in text: | 31 | if '@' in text: |
26 | text, category = text.split('@', 1) | 32 | text, category = text.split('@', 1) |
27 | category = category.strip() | 33 | category = category.strip() |
28 | 34 | ||
29 | activity = text.strip() | 35 | activity = Activity(text.strip(), description, category) |
36 | activity.tags = tags | ||
37 | |||
38 | return activity | ||
39 | |||
40 | |||
41 | def parse_tags(tokens): | ||
42 | return [token.lstrip('#') for token in tokens if token.startswith('#')] | ||
43 | |||
30 | 44 | ||
31 | return Activity(activity, description, category) | 45 | def strip_tags(tokens): |
46 | return ' '.join([token for token in tokens if not token.startswith('#')]) | ||