From 1513c0d9c6e875584b45a8cd1dcdb0e73edfdf62 Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Mon, 1 Jul 2013 00:55:23 +0200 Subject: [PATCH] Some work on `models.Aspect.getUsers()` done --- diaspy/connection.py | 5 ++++- diaspy/models.py | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/diaspy/connection.py b/diaspy/connection.py index c2d185b..9ce4057 100644 --- a/diaspy/connection.py +++ b/diaspy/connection.py @@ -38,7 +38,10 @@ class Connection(): """ self.pod = pod self.session = requests.Session() - self._setlogin(username, password) + try: + self._setlogin(username, password) + except Exception as e: + raise LoginError('cannot create login data (caused by: {0}'.format(e)) def get(self, string, headers={}, params={}): """This method gets data from session. diff --git a/diaspy/models.py b/diaspy/models.py index 72041a5..555715b 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -21,7 +21,27 @@ class Aspect(): def getUsers(self): """Returns list of users who are listed in this aspect. """ - return [] + start_regexp = re.compile('') + ajax = ajax[begin:end] + all_users = userline_regexp.findall(ajax) + usernames = [line[35:-4] for line in all_users] + personid_regexp = 'alt="{USERNAME}" class="avatar" data-person_id="[0-9]+"' + person_ids = [re.compile(personid_regexp.replace('{USERNAME}', name)).search(ajax).group(0) for name in usernames] + personids = [] + for n, line in enumerate(person_ids): + i = -2 + id = '' + while line[i].isdigit(): + id += line[i] + i -= 1 + personids.append((usernames[n], id)) + users = personids + return users def addUser(self, user_id): """Add user to current aspect. -- 2.25.1