示例#1
0
 def fetchguid(self):
     """Fetch user data and posts using guid.
     """
     if self.guid:
         request = self._connection.get('people/{0}.json'.format(self.guid))
         self._postproc(request)
     else:
         raise errors.UserError('GUID not set')
示例#2
0
 def getHCard(self):
     """Returns XML string containing user HCard.
     """
     request = self._connection.get('hcard/users/{0}'.format(self['guid']))
     if request.status_code != 200:
         raise errors.UserError(
             'could not fetch hcard for user: {0}'.format(self['guid']))
     return request.text
示例#3
0
 def fetchprofile(self):
     """Fetches user data.
     """
     data = search.Search(self._connection).user(self['handle'])
     if not data:
         raise errors.UserError(
             'user with handle "{0}" has not been found on pod "{1}"'.
             format(self['handle'], self._connection.pod))
     else:
         self.data = data[0]
示例#4
0
    def fetchguid(self, fetch_stream=True):
        """Fetch user data and posts (if fetch_stream is True) using guid.
		"""
        if self['guid']:
            request = self._connection.get('people/{0}.json'.format(
                self['guid']))
            self._postproc(request)
            if fetch_stream: self._fetchstream()
        else:
            raise errors.UserError('GUID not set')
示例#5
0
    def deletePhoto(self, photo_id):
        """
		:param photo_id: Photo ID to delete.
		:type photo_id: int

		--> DELETE /photos/{PHOTO_ID} HTTP/1.1
		<-- HTTP/1.1 204 No Content
		"""
        request = self._connection.delete('/photos/{0}'.format(photo_id))
        if request.status_code != 204:
            raise errors.UserError(
                'could not delete photo_id: {0}'.format(photo_id))
示例#6
0
    def _postproc(self, request):
        """Makes necessary modifications to user data and
        sets up a stream.

        :param request: request object
        :type request: request
        """
        if request.status_code != 200:
            raise Exception('wrong error code: {0}'.format(
                request.status_code))
        request = request.json()
        if not len(request):
            raise errors.UserError(
                'cannot extract user data: no posts to analyze')
        self.data = self._finalize_data(request[0]['author'])
示例#7
0
    def getPhotos(self):
        """Gets and sets this User()'s photo data.

		:returns: dict

		--> GET /people/{GUID}/photos.json HTTP/1.1

		<-- HTTP/1.1 200 OK

		{
			"photos":[
				{
					"id":{photo_id},
					"guid":"{photo_guid}",
					"created_at":"2018-03-08T23:48:31.000Z",
					"author":{
						"id":{author_id},
						"guid":"{author_guid}",
						"name":"{author_name}",
						"diaspora_id":"{diaspora_id}",
						"avatar":{"small":"{avatar_url_small}","medium":"{avatar_url_medium}","large":"{avatar_url_large}"}
					},
					"sizes":{
						"small":"{photo_url}",
						"medium":"{photo_url}",
						"large":"{photo_url}"
					},
					"dimensions":{"height":847,"width":998},
					"status_message":{
						"id":{post_id}
					}
				},{ ..
		}

		if there are no photo's it returns:
		{"photos":[]}
		"""

        request = self._connection.get('/people/{0}/photos.json'.format(
            self['guid']))
        if request.status_code != 200:
            raise errors.UserError(
                'could not fetch photos for user: {0}'.format(self['guid']))

        json = request.json()
        if json: self.photos = json['photos']
        return json['photos']
示例#8
0
    def getHCard(self):
        """Returns json containing user HCard.
		--> /people/{guid}/hovercard.json?_={timestamp}

		<-- HTTP/2.0 200 OK
		{
			"id":123,
			"guid":"1234567890abcdef",
			"name":"test",
			"diaspora_id":"*****@*****.**",
			"contact":false,
			"profile":{
				"avatar":"https://nicetesturl.url/image.jpg",
				"tags":["tag1", "tag2", "tag3", "tag4", "tag5"]}
		}
		"""
        timestamp = int(time.mktime(time.gmtime()))
        request = self._connection.get(
            '/people/{0}/hovercard.json?_={}'.format(self['guid'], timestamp))
        if request.status_code != 200:
            raise errors.UserError(
                'could not fetch hcard for user: {0}'.format(self['guid']))
        return request.json()