Unnecessarily complex code removed from Aspects().getID()
authorMarek Marecki <triviuss@gmail.com>
Mon, 20 May 2013 18:49:38 +0000 (20:49 +0200)
committerMarek Marecki <triviuss@gmail.com>
Mon, 20 May 2013 18:49:38 +0000 (20:49 +0200)
diaspy/connection.py
diaspy/streams.py

index 1fbba9fa443c29d67c13bf3dc6dcdf4c4cf4b8f1..5298565f90f77b6f8c80c7f339f75de2ba029766 100644 (file)
@@ -30,7 +30,7 @@ class Connection():
         self.session = requests.Session()
         self._setlogin(username, password)
 
-    def get(self, string):
+    def get(self, string, headers={}, params={}):
         """This method gets data from session.
         Performs additional checks if needed.
 
@@ -40,7 +40,7 @@ class Connection():
         :param string: URL to get without the pod's URL and slash eg. 'stream'.
         :type string: str
         """
-        return self.session.get('{0}/{1}'.format(self.pod, string))
+        return self.session.get('{0}/{1}'.format(self.pod, string), params=params, headers=headers)
 
     def post(self, string, data, headers={}, params={}):
         """This method posts data to session.
index 7c9b76743d6b6d2bb9afcaaad9420bdc29935b68..39080e32ad7f861ea8343de3b3bef1e0f3b2c0ee 100644 (file)
@@ -1,5 +1,6 @@
 import json
 import re
+import time
 from diaspy.models import Post
 
 """Docstrings for this module are taken from:
@@ -16,6 +17,8 @@ class Generic:
     """
     _location = 'stream.json'
     _stream = []
+    #   since epoch
+    max_time = int(time.mktime(time.gmtime()))
 
     def __init__(self, connection, location=''):
         """
@@ -97,6 +100,15 @@ class Generic:
         """
         self._stream = self._obtain()
 
+    def more(self):
+        """Tries to download more (older ones) Posts from Stream.
+        """
+        self.max_time -= 3000000
+        params = {'max_time':self.max_time}
+        request = self._connection.get('{0}', params=params)
+        if request.status_code != 200:
+            raise Exception('wrong status code: {0}'.format(request.status_code))
+
 
 class Outer(Generic):
     """Object used by diaspy.models.User to represent
@@ -231,10 +243,9 @@ class Aspects(Generic):
         :returns: int
         """
         id = -1
-        regexp = re.compile("a_id=[0-9]+'>\s+{0}".format(aspect))
-        result = regexp.search(self._connection.get('aspects').text)
-        if result is not None:
-            id = int(re.compile('[0-9]+').search(result.group(0)).group(0))
+        aspects = self._connection.getUserInfo()['aspects']
+        for item in aspects:
+            if item['name'] == aspect: id = item['id']
         return id
 
     def filterByIDs(self, ids):