def _do_fetch(self, fetch):
if fetch == 'posts':
- if self['handle'] and self['guid']: self.fetchguid(self['guid'])
- elif self['guid'] and not self['handle']: self.fetchguid(self['guid'])
- elif self['handle'] and not self['guid']: self.fetchhandle(self['handle'])
+ if self['handle'] and self['guid']: self.fetchguid()
+ elif self['guid'] and not self['handle']: self.fetchguid()
+ elif self['handle'] and not self['guid']: self.fetchhandle()
elif fetch == 'data' and len(self['handle']):
- self.fetchprofile(self['handle'])
+ self.fetchprofile()
- def _sephandle(self, handle):
+ def _sephandle(self):
"""Separate D* handle into pod pod and user.
- :param handle: diaspora id: user@pod.example.com
- :type handle: str
:returns: two-tuple (pod, user)
"""
- if re.match('^[a-zA-Z]+[a-zA-Z0-9_-]*@[a-z0-9.]+\.[a-z]+$', handle) is None:
- raise Exception('invalid handle: {0}'.format(handle))
- handle = handle.split('@')
+ if re.match('^[a-zA-Z]+[a-zA-Z0-9_-]*@[a-z0-9.]+\.[a-z]+$', self['handle']) is None:
+ raise Exception('invalid handle: {0}'.format(self['handle']))
+ handle = self['handle'].split('@')
pod, user = handle[1], handle[0]
return (pod, user)
('avatar', 'image_urls'),
]
self.data = self._finalize_data(request[0]['author'], names)
- self.stream = Outer(self._connection, location='people/{0}.json'.format(self.data['guid']))
+ self.stream = Outer(self._connection, location='people/{0}.json'.format(self['guid']))
- def fetchhandle(self, diaspora_id, protocol='https'):
+ def fetchhandle(self, protocol='https'):
"""Fetch user data and posts using Diaspora handle.
"""
- pod, user = self._sephandle(diaspora_id)
+ pod, user = self._sephandle()
request = self._connection.session.get('{0}://{1}/u/{2}.json'.format(protocol, pod, user))
self._postproc(request)
- def fetchguid(self, guid):
+ def fetchguid(self):
"""Fetch user data and posts using guid.
"""
- request = self._connection.get('people/{0}.json'.format(guid))
+ request = self._connection.get('people/{0}.json'.format(self['guid']))
self._postproc(request)
- def fetchprofile(self, diaspora_id, protocol='https'):
+ def fetchprofile(self, protocol='https'):
"""Fetch user data using Diaspora handle.
"""
- pod, user = self._sephandle(diaspora_id)
- request = self._connection.get('people.json?q={0}'.format(diaspora_id))
+ request = self._connection.get('people.json?q={0}'.format(self['handle']))
if request.status_code != 200:
raise Exception('wrong error code: {0}'.format(request.status_code))
else: