From dde4ddb730a5a9a65829d7359444e25aacdc2742 Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Sat, 10 Aug 2013 11:27:47 +0200 Subject: [PATCH] Fixed some bugs in streams --- diaspy/streams.py | 25 +++++++++++++++++-------- setup.py | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/diaspy/streams.py b/diaspy/streams.py index 6da1d82..36ff236 100644 --- a/diaspy/streams.py +++ b/diaspy/streams.py @@ -55,7 +55,9 @@ class Generic(): """Obtains stream from pod. """ params = {} - if max_time: params['max_time'] = max_time + if max_time: + params['max_time'] = max_time + params['_'] = self.max_time request = self._connection.get(self._location, params=params) if request.status_code != 200: raise errors.StreamError('wrong status code: {0}'.format(request.status_code)) @@ -64,12 +66,12 @@ class Generic(): def _expand(self, new_stream): """Appends older posts to stream. """ - ids = [post.post_id for post in self._stream] + ids = [post.id for post in self._stream] stream = self._stream for post in new_stream: - if post.post_id not in ids: + if post.id not in ids: stream.append(post) - ids.append(post.post_id) + ids.append(post.id) self._stream = stream def _update(self, new_stream): @@ -125,17 +127,24 @@ class Generic(): new_stream = self._obtain(max_time=max_time) self._expand(new_stream) + def copy(self): + """Returns copy (list of posts) of current stream. + """ + return [p for p in self._stream] + class Outer(Generic): """Object used by diaspy.models.User to represent stream of other user. """ - def _obtain(self): - """Obtains stream of other user. + def _obtain(self, max_time=0): + """Obtains stream from pod. """ - request = self._connection.get(self._location) + params = {} + if max_time: params['max_time'] = max_time + request = self._connection.get(self._location, params=params) if request.status_code != 200: - raise error.StreamError('wrong status code: {0}'.format(request.status_code)) + raise errors.StreamError('wrong status code: {0}'.format(request.status_code)) return [Post(self._connection, post['id']) for post in request.json()] diff --git a/setup.py b/setup.py index e09a709..663a1b2 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages setup(name='diaspy', - version='0.3.0', + version='0.3.1', author='Moritz Kiefer', author_email='moritz.kiefer@gmail.com', url='https://github.com/Javafant/diaspora-api', -- 2.25.1