blob: 8d93391ead3889724072bbfd569ebdaba3d1c8c2 (
plain)
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
|
# vim: set filencoding=utf8
"""
Activity Parser
@author: Mike Crute (mcrute@ag.com)
@organization: American Greetings Interactive
@date: February 04, 2010
"""
class Activity(object):
def __init__(self, activity, description=None, category=None):
self.activity = activity
self.description = description
self.category = category
self.tags = []
def parse_activity(text):
description = None
tags = []
if ',' in text:
text, description = text.split(',', 1)
description = description.strip()
tokens = description.split(' ')
tags = parse_tags(tokens)
description = strip_tags(tokens)
category = None
if '@' in text:
text, category = text.split('@', 1)
category = category.strip()
activity = Activity(text.strip(), description, category)
activity.tags = tags
return activity
def parse_tags(tokens):
return [token.lstrip('#') for token in tokens if token.startswith('#')]
def strip_tags(tokens):
return ' '.join([token for token in tokens if not token.startswith('#')])
|