From 961277f67fda683f72273a012507373497b0b2c6 Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Thu, 22 Aug 2013 00:16:37 +0200 Subject: [PATCH] Regular expressions fixed --- diaspy/__init__.py | 2 +- diaspy/models.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/diaspy/__init__.py b/diaspy/__init__.py index 1a7d7c4..1d40d04 100644 --- a/diaspy/__init__.py +++ b/diaspy/__init__.py @@ -7,4 +7,4 @@ import diaspy.notifications as notifications import diaspy.settings as settings -__version__ = '0.3.2.1' +__version__ = '0.4.0' diff --git a/diaspy/models.py b/diaspy/models.py index 9df0ae7..fb592cc 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -148,9 +148,10 @@ class Aspect(): class Notification(): """This class represents single notification. """ - _who_regexp = re.compile(r'/people/[0-9a-z]+" class=\'hovercardable') + _who_regexp = re.compile(r'/people/[0-9a-f]+" class=\'hovercardable') _when_regexp = re.compile(r'[0-9]{4,4}(-[0-9]{2,2}){2,2} [0-9]{2,2}(:[0-9]{2,2}){2,2} UTC') - _aboutid_regexp = re.compile(r'/posts/[0-9]+') + _aboutid_regexp = re.compile(r'/posts/[0-9a-f]+') + _htmltag_regexp = re.compile('') def __init__(self, connection, data): self._connection = connection @@ -167,7 +168,7 @@ class Notification(): def __str__(self): """Returns notification note. """ - string = re.sub('', '', self.data['note_html']) + string = re.sub(self._htmltag_regexp, '', self.data['note_html']) string = string.strip().split('\n')[0] while ' ' in string: string = string.replace(' ', ' ') return string @@ -178,7 +179,8 @@ class Notification(): return '{0}: {1}'.format(self.when(), str(self)) def about(self): - """Returns id of post about which the notification is informing. + """Returns id of post about which the notification is informing OR: + If the id is None it means that it's about user so .who() is called. """ about = self._aboutid_regexp.search(self.data['note_html']) if about is None: about = self.who() -- 2.25.1