From: Marek Marecki Date: Sun, 30 Jun 2013 22:55:23 +0000 (+0200) Subject: Some work on `models.Aspect.getUsers()` done X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1513c0d9c6e875584b45a8cd1dcdb0e73edfdf62;p=diaspy.git Some work on `models.Aspect.getUsers()` done --- 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.