From 33b34938a915dadaf6556fcdda249c6f31760b74 Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Mon, 20 May 2013 20:49:38 +0200 Subject: [PATCH] Unnecessarily complex code removed from Aspects().getID() --- diaspy/connection.py | 4 ++-- diaspy/streams.py | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/diaspy/connection.py b/diaspy/connection.py index 1fbba9f..5298565 100644 --- a/diaspy/connection.py +++ b/diaspy/connection.py @@ -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. diff --git a/diaspy/streams.py b/diaspy/streams.py index 7c9b767..39080e3 100644 --- a/diaspy/streams.py +++ b/diaspy/streams.py @@ -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): -- 2.25.1