From e5b83c4b51d7949f0da0997f90856c0a612c58c9 Mon Sep 17 00:00:00 2001 From: CYBERDEViLNL Date: Mon, 5 Nov 2018 13:40:00 +0100 Subject: [PATCH] * `diaspy.people.User().handle()` now returns `diaspora_id` instead of `handle` wich doesn't exist anymore. * Apparently `/u/username.json` retuns 404 so `diaspy.people.User().fetchhandle()` now fetches data using `diaspy.people.User().fetchprofile()`. * Some formatting fixes in `settings.py` * `tests.py` should succeed now. --- Changelog.markdown | 4 +++- diaspy/people.py | 17 +++++++---------- diaspy/settings.py | 4 ++-- tests.py | 6 +++--- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Changelog.markdown b/Changelog.markdown index fd03c25..6b60205 100644 --- a/Changelog.markdown +++ b/Changelog.markdown @@ -48,6 +48,7 @@ Note: In this version indentation changed from spaces to tabs. * __upd__: Update `diaspy.models.Post()` it's interaction data after liked, * __upd__: `diaspy.connection.Connection()`'s `getUserData()` method will now set the `Connection()` object it's `self._userdata`, * __upd__: Posts obtained by `diaspy.streams.Generic()` are now fetched once instead of twice, +* __upd__: `tests.py`, * __fix__: Streams seemed to miss posts on `more()` method, should be fixed now. Also a new dependency: `dateutil`, @@ -72,7 +73,8 @@ Note: In this version indentation changed from spaces to tabs. * __rem__: `_obtain()` from `diaspy.streams.Outer()`, it was the same as `_obtain()` in `diaspy.streams.Generic()`, * __rem__: `diaspy.models.Post()` its `update()` method since it is deprecated for a while now, -* __rem__: `backtime` parameter removed from `diaspy.streams.Generic.more()`. +* __rem__: `backtime` parameter removed from `diaspy.streams.Generic.more()`, +* __rem__: `protocol` parameter removed from `diaspy.people.User().fetchhandle()`. ---- diff --git a/diaspy/people.py b/diaspy/people.py index cebfb92..c16cb16 100644 --- a/diaspy/people.py +++ b/diaspy/people.py @@ -68,7 +68,7 @@ class User(): self.stream = [] self.data = { 'guid': guid, - 'handle': handle, + 'diaspora_id': handle, 'id': id, } self.photos = [] @@ -85,8 +85,7 @@ class User(): return '{0} ({1})'.format(self.handle(), self.guid()) def handle(self): - if 'handle' in self.data: return self['handle'] - return self.data.get('diaspora_id', 'Unknown handle') + return self.data.get('diaspora_id', 'Unknown Diaspora ID') def guid(self): return self.data.get('guid', '') @@ -103,7 +102,7 @@ class User(): if fetch == 'posts': if self.handle() and not self['guid']: self.fetchhandle() else: self.fetchguid() - elif fetch == 'data' and self['handle']: + elif fetch == 'data' and self['diaspora_id']: self.fetchprofile() def _finalize_data(self, data): @@ -121,14 +120,12 @@ class User(): """ if request.status_code != 200: raise Exception('wrong error code: {0}'.format(request.status_code)) data = request.json() - self.data = self._finalize_data(data) + self.data.update(self._finalize_data(data)) - def fetchhandle(self, protocol='https'): - """Fetch user data and posts using Diaspora handle. + def fetchhandle(self): + """Fetch user data and posts using Diaspora ID (previously known as handle). """ - pod, user = sephandle(self['handle']) - request = self._connection.get('{0}://{1}/u/{2}.json'.format(protocol, pod, user), direct=True) - self._postproc(request) + self.fetchprofile() self._fetchstream() def fetchguid(self, fetch_stream=True): diff --git a/diaspy/settings.py b/diaspy/settings.py index 53d7ab5..e0d47b4 100644 --- a/diaspy/settings.py +++ b/diaspy/settings.py @@ -123,7 +123,7 @@ class Account(): if BS4_SUPPORT: soup = BeautifulSoup(request.text, 'lxml') language = soup.find('select', {"id": "user_language"}) - return [(option.text, option['value']) for option in language.findAll('option')] + return [(option['value'], option.text) for option in language.findAll('option')] else: return self.language_option_regexp.findall(request.text) @@ -262,7 +262,7 @@ class Profile(): else: month_option = -1 elif named_month: month_option = month_option.text - else: month_option = month_option['value'] + else: month_option = int(month_option['value']) day = soup.find('select', {"id": "profile_date_day"}) day_option = day.find('option', selected=True) diff --git a/tests.py b/tests.py index ea83a18..d35e262 100644 --- a/tests.py +++ b/tests.py @@ -166,7 +166,7 @@ class UserTests(unittest.TestCase): def testGettingUserByHandlePosts(self): user = diaspy.people.User(test_connection, handle=testconf.diaspora_id) self.assertEqual(testconf.guid, user['guid']) - self.assertEqual(testconf.diaspora_id, user['handle']) + self.assertEqual(testconf.diaspora_id, user['diaspora_id']) self.assertEqual(testconf.diaspora_name, user['name']) self.assertIn('id', user.data) self.assertIn('avatar', user.data) @@ -174,10 +174,10 @@ class UserTests(unittest.TestCase): def testGettingUserByGUID(self): user = diaspy.people.User(test_connection, guid=testconf.guid) - self.assertEqual(testconf.diaspora_id, user['handle']) + self.assertEqual(testconf.diaspora_id, user['diaspora_id']) self.assertEqual(testconf.diaspora_name, user['name']) self.assertIn('id', user.data) - self.assertIn('avatar', user.data) + self.assertIn('avatar', user.data['profile']) self.assertEqual(type(user.stream), diaspy.streams.Outer) def testReprMethod(self): -- 2.25.1