Esempio n. 1
0
 def forward(self, message, text):
     res = None
     try:
         if message.ID.feed_type == 'STATUS':
             res = self.renren_request(
                 method='status.forward',
                 status=text,
                 forward_id=message.ID.status_id,
                 forward_owner=message.ID.source_user_id,
             )
         elif message.ID.feed_type != 'OTHER':
             res = self.renren_request(method='share.share',
                                       type=str({
                                           'BLOG': 1,
                                           'PHOTO': 2,
                                           'SHARE': 20
                                       }[message.parsed.feed_type]),
                                       ugc_id=message.ID.status_id,
                                       user_id=message.ID.source_user_id,
                                       comment=text)
         else:
             return BooleanWrappedData(False, {
                 'errors': ['SNSAPI_NOT_SUPPORTED'],
             })
     except Exception as e:
         logger.warning('Catch exception: %s', e)
         return BooleanWrappedData(False, {
             'errors': ['PLATFORM_'],
         })
     if res:
         return BooleanWrappedData(True)
     else:
         return BooleanWrappedData(False, {
             'errors': ['PLATFORM_'],
         })
Esempio n. 2
0
 def reply(self, statusId, text):
     res = None
     flag = False
     try:
         # The order in the bracket is important since there
         # exists "SHARE_XXXX" type. In order to figure out
         # the actual type, SHARE must be put in the first position.
         for msg_type in [
                 "SHARE", "BLOG", "PHOTO", "ALBUM", "STATUS", "VIDEO"
         ]:
             if msg_type in statusId.feed_type:
                 flag = True
                 break
         if flag:
             res = self.renren_request(method="comment/put",
                                       content=text,
                                       commentType=msg_type,
                                       entryOwnerId=statusId.source_user_id,
                                       entryId=statusId.resource_id)
         else:
             return BooleanWrappedData(False, {
                 'errors': ['SNSAPI_NOT_SUPPORTED'],
             })
     except Exception, e:
         logger.warning('Catch exception: %s', e)
         return BooleanWrappedData(False, {
             'errors': ['PLATFORM_'],
         })
Esempio n. 3
0
 def _update_blog(self, text, title):
     try:
         self.renren_request(method='blog/put', title=title, content=text)
         return BooleanWrappedData(True)
     except:
         return BooleanWrappedData(False, {
             'errors': ['PLATFORM_'],
         })
Esempio n. 4
0
 def _update_status(self, text):
     try:
         self.renren_request(method='status/put', content=text)
         return BooleanWrappedData(True)
     except:
         return BooleanWrappedData(False, {
             'errors': ['PLATFORM_'],
         })
Esempio n. 5
0
 def _update_share_link(self, text, link):
     try:
         self.renren_request(method='share.share',
                             type='6',
                             url=link,
                             comment=text)
         return BooleanWrappedData(True)
     except:
         return BooleanWrappedData(False, {'errors': ['PLATFORM_']})
Esempio n. 6
0
 def _update_photo(self, text, pic):
     try:
         self.renren_request(
             method='photo/upload',
             description=text,
             file={'upload': ('%d.jpg' % int(time.time()), pic)})
         return BooleanWrappedData(True)
     except:
         return BooleanWrappedData(False, {
             'errors': ['PLATFORM_'],
         })
Esempio n. 7
0
 def reply(self, statusId, text):
     #NOTE: you can mix API1 and API2.
     #NOTE: API2 is more better on comment
     res = None
     try:
         if statusId.feed_type == 'STATUS':
             res = self.renren_request(
                 method='status.addComment',
                 status_id=statusId.status_id,
                 owner_id=statusId.source_user_id,
                 content=text
             )
         elif statusId.feed_type == 'SHARE':
             res = self.renren_request(
                 method='share.addComment',
                 share_id=statusId.status_id,
                 user_id=statusId.source_user_id,
                 content=text
             )
         elif statusId.feed_type == 'BLOG':
             res = self.renren_request(
                 method='blog.addComment',
                 id=statusId.status_id,
                 #FIXME: page_id, uid
                 uid=statusId.source_user_id,
                 content=text
             )
         elif statusId.feed_type == 'PHOTO':
             res = self.renren_request(
                 method='photos.addComment',
                 uid=statusId.source_user_id,
                 content=text,
                 #FIXME: aid, pid
                 pid=statusId.status_id
             )
         else:
             return BooleanWrappedData(False, {
                 'errors' : ['SNSAPI_NOT_SUPPORTED'],
             })
     except:
         return BooleanWrappedData(False, {
             'errors': ['PLATFORM_'],
         })
     if res:
         return BooleanWrappedData(True)
     else:
         return BooleanWrappedData(False, {
             'errors' : ['PLATFORM_'],
         })
Esempio n. 8
0
    def forward(self, message, text):
        res = None
        if not message.platform == self.platform:
            return super(RenrenFeed, self).forward(message, text)
        else:
            try:
                if message.ID.feed_type == 'UPDATE_STATUS':
                    res = self.renren_request(
                        method='status/share',
                        content=text,
                        statusId=message.ID.resource_id,
                        ownerId=message.ID.source_user_id,
                    )

                elif message.ID.feed_type != 'OTHER':
                    for msg_type in [
                            "SHARE", "BLOG", "PHOTO", "ALBUM", "VIDEO"
                    ]:
                        if msg_type in message.ID.feed_type:
                            break
                    # The order in the bracket is important since there
                    # exists "SHARE_XXXX" type. In order to figure out
                    # the actual type, SHARE must be put in the first position.
                    res = self.renren_request(
                        method='share/ugc/put',
                        ugcType="TYPE_" + msg_type,
                        ugcId=message.ID.resource_id,
                        # Here message.ID.resource_id is the proper id
                        # for forwarding these messages instead of message.ID.status_id
                        ugcOwnerId=message.ID.source_user_id,
                        comment=text)
                else:
                    return BooleanWrappedData(False, {
                        'errors': ['SNSAPI_NOT_SUPPORTED'],
                    })
            except Exception as e:
                logger.warning('Catch exception: %s', e)
                return BooleanWrappedData(False, {
                    'errors': ['PLATFORM_'],
                })
        if res:
            return BooleanWrappedData(True)
        else:
            return BooleanWrappedData(False, {
                'errors': ['PLATFORM_'],
            })
Esempio n. 9
0
 def update(self, text, **kwargs):
     coder = int(''.join(
         map(lambda t: str(int(t)),
             ['title' in kwargs, 'link' in kwargs, 'pic' in kwargs][::-1])))
     try:
         update_what = {
             0: self._update_status,
             1: self._update_blog,
             10: self._update_share_link,
             100: self._update_photo
         }[coder]
     except:
         return BooleanWrappedData(False, {
             'errors': ['SNSAPI_NOT_SUPPORTED'],
         })
     return update_what(text, **kwargs)
Esempio n. 10
0
                res = self.renren_request(method="comment/put",
                                          content=text,
                                          commentType=msg_type,
                                          entryOwnerId=statusId.source_user_id,
                                          entryId=statusId.resource_id)
            else:
                return BooleanWrappedData(False, {
                    'errors': ['SNSAPI_NOT_SUPPORTED'],
                })
        except Exception, e:
            logger.warning('Catch exception: %s', e)
            return BooleanWrappedData(False, {
                'errors': ['PLATFORM_'],
            })
        if res:
            return BooleanWrappedData(True)
        else:
            return BooleanWrappedData(False, {
                'errors': ['PLATFORM_'],
            })

    @require_authed
    def forward(self, message, text):
        res = None
        if not message.platform == self.platform:
            return super(RenrenFeed, self).forward(message, text)
        else:
            try:
                if message.ID.feed_type == 'UPDATE_STATUS':
                    res = self.renren_request(
                        method='status/share',