Fixed list generation in diaspy/client.py
authorMarek Marecki <triviuss@gmail.com>
Mon, 25 Mar 2013 16:16:38 +0000 (17:16 +0100)
committerMarek Marecki <triviuss@gmail.com>
Mon, 25 Mar 2013 16:16:38 +0000 (17:16 +0100)
diaspy/client.py

index 2dc088e5942e580c94d6403dfa03d9068f0196bc..0ec0074eb63185074a8f56bb6f25483ccecbcdaa 100644 (file)
@@ -20,6 +20,7 @@ class Client:
         """
         self._token_regex = re.compile(r'content="(.*?)"\s+name="csrf-token')
         self.pod = pod
+        self.logged_in = False
         self.session = requests.Session()
         self._setlogindata(username, password)
 
@@ -56,6 +57,7 @@ class Client:
                               headers={'accept': 'application/json'})
         
         if r.status_code != 201: raise Exception('{0}: Login failed.'.format(r.status_code))
+        else: self.logged_in = True
     
     def post(self, text, aspect_id='public', photos=None):
         """This function sends a post to an aspect
@@ -127,11 +129,7 @@ class Client:
             raise Exception('wrong status code: {0}'.format(r.status_code))
 
         stream = r.json()
-
-        posts = []
-
-        for post in stream: 
-            posts.append(diaspy.models.Post(str(post['id']), self))
+        posts = [ diaspy.models.Post(str(post['id']), self) for post in stream ]
 
         return posts
 
@@ -166,11 +164,7 @@ class Client:
             raise Exception('wrong status code: {0}'.format(r.status_code))
 
         mentions = r.json()
-
-        posts = []
-
-        for post in mentions:
-            posts.append(diaspy.models.Post(str(post['id']), self))
+        posts = [ diaspy.models.Post(str(post['id']), self) for post in mentions ]
 
         return posts
 
@@ -190,11 +184,7 @@ class Client:
             raise Exception('wrong status code: {0}'.format(r.status_code))
 
         tagged_posts = r.json()
-
-        posts = []
-
-        for post in tagged_posts:
-            posts.append(diaspy.models.Post(str(post['id']), self))
+        posts = [ diaspy.models.Post(str(post['id']), self) for post in tagged_posts ]
 
         return posts
 
@@ -281,11 +271,7 @@ class Client:
             raise Exception('wrong status code: {0}'.format(r.status_code))
 
         mailbox = r.json()
-
-        conversations = []
-
-        for conversation in mailbox:
-            conversations.append(diaspy.conversations.Conversation(str(conversation['conversation']['id']), self))
+        conversations = [ diaspy.conversations.Conversation(str(conversation['conversation']['id']), self) for conversation in mailbox ]
 
         return conversations