Ejemplo n.º 1
0
    def SaveToPocket(self, user, action, orgUrl):
        INSTAPAPER_API_ADD_URL = 'https://www.instapaper.com/api/add'

        web.header('Content-type', "text/html; charset=utf-8")
        
        T_INFO = u"""<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
            <title>%s</title></head><body><p style="text-align:center;font-size:1.5em;">%s</p></body></html>"""
        if not user.pocket_access_token:
            info = T_INFO % ('Pocket unauthorized', 'Unauthorized Pocket!<br/>Please authorize your KindleEar application firstly.')
            return info.encode('utf-8')
            
        title = web.input().get('t', '')
        tkHash = web.input().get("h", '')
        if hashlib.md5(user.pocket_acc_token_hash).hexdigest() != tkHash:
            info = T_INFO % ('Action rejected', 'Hash not match!<br/>KindleEar refuse to execute your command.')
            return info.encode('utf-8')
            
        pocket = Pocket(POCKET_CONSUMER_KEY)
        pocket.set_access_token(user.pocket_access_token)
        try:
            item = pocket.add(url=orgUrl, title=title, tags='KindleEar')
        except Exception as e:
            info = T_INFO % ('Failed to save', _('Failed save to Pocket.<br/>') + str(e))
        else:
            info = _("'%s'<br/><br/>Saved to your Pocket account.") % title
            info += u'''<br/><p style="text-align:right;color:red;">by KindleEar &nbsp;</p>
                <br/><hr/><p style="color:silver;">'''
            info += _('See details below:<br/><br/>%s') % repr(item)
            info = T_INFO % ('Saved to pocket', info)
        
        return info.encode('utf-8')
Ejemplo n.º 2
0
    def GET(self, authType):
        if authType.lower() != 'pocket':
            return 'Auth Type(%s) Unsupported!' % authType

        user = self.getcurrentuser()
        reUrl = web.input().get('redirect')
        if not reUrl:
            reUrl = '/advsettings'

        pocket = Pocket(POCKET_CONSUMER_KEY)
        request_token = main.session.get('pocket_request_token', '')
        try:
            resp = pocket.get_access_token(request_token)
            user.pocket_access_token = resp.get('access_token', '')
            user.pocket_acc_token_hash = hashlib.md5(
                user.pocket_access_token).hexdigest()
            user.put()
            return self.render('tipsback.html',
                               'Success authorized',
                               urltoback='/advarchive',
                               tips=_('Success authorized by Pocket!'))
        except Exception as e:
            user.pocket_access_token = ''
            user.pocket_acc_token_hash = ''
            user.pocket = False
            user.put()
            return self.render(
                'tipsback.html',
                'Failed to authorzi',
                urltoback='/advarchive',
                tips=
                _('Failed to request authorization of Pocket!<hr/>See details below:<br/><br/>%s'
                  ) % str(e))
Ejemplo n.º 3
0
    def SaveToPocket(self, user, action, orgUrl):
        INSTAPAPER_API_ADD_URL = 'https://www.instapaper.com/api/add'

        web.header('Content-type', "text/html; charset=utf-8")
        
        T_INFO = u"""<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
            <title>%s</title></head><body><p style="text-align:center;font-size:1.5em;">%s</p></body></html>"""
        if not user.pocket_access_token:
            info = T_INFO % ('Pocket unauthorized', 'Unauthorized Pocket!<br/>Please authorize your KindleEar application firstly.')
            return info.encode('utf-8')
            
        title = web.input().get('t', '')
        tkHash = web.input().get("h", '')
        if hashlib.md5(user.pocket_acc_token_hash).hexdigest() != tkHash:
            info = T_INFO % ('Action rejected', 'Hash not match!<br/>KindleEar refuse to execute your command.')
            return info.encode('utf-8')
            
        pocket = Pocket(POCKET_CONSUMER_KEY)
        pocket.set_access_token(user.pocket_access_token)
        try:
            item = pocket.add(url=orgUrl, title=title, tags='KindleEar')
        except Exception as e:
            info = T_INFO % ('Failed to save', _('Failed save to Pocket.<br/>') + str(e))
        else:
            info = _("'%s'<br/><br/>Saved to your Pocket account.") % title
            info += u'''<br/><p style="text-align:right;color:red;">by KindleEar &nbsp;</p>
                <br/><hr/><p style="color:silver;">'''
            info += _('See details below:<br/><br/>%s') % repr(item)
            info = T_INFO % ('Saved to pocket', info)
        
        return info.encode('utf-8')
Ejemplo n.º 4
0
 def GET(self, authType):
     if authType.lower() != 'pocket':
         return 'Auth Type(%s) Unsupported!' % authType
         
     user = self.getcurrentuser()
     cbUrl = urlparse.urljoin(DOMAIN, '/oauth2cb/pocket?redirect=/advarchive')
     pocket = Pocket(POCKET_CONSUMER_KEY, cbUrl)
     try:
         request_token = pocket.get_request_token()
         url = pocket.get_authorize_url(request_token)
     except Exception as e:
         return self.render('tipsback.html', 'Authorization Error', urltoback='/advarchive', tips=_('Authorization Error!<br/>%s') % str(e))
     
     main.session['pocket_request_token'] = request_token
     raise web.seeother(url)
Ejemplo n.º 5
0
 def GET(self, authType):
     if authType.lower() != 'pocket':
         return 'Auth Type(%s) Unsupported!' % authType
         
     user = self.getcurrentuser()
     cbUrl = urlparse.urljoin(DOMAIN, '/oauth2cb/pocket?redirect=/advarchive')
     pocket = Pocket(POCKET_CONSUMER_KEY, cbUrl)
     try:
         request_token = pocket.get_request_token()
         url = pocket.get_authorize_url(request_token)
     except Exception as e:
         return self.render('tipsback.html', 'Authorization Error', urltoback='/advarchive', tips=_('Authorization Error!<br/>%s') % str(e))
     
     main.session['pocket_request_token'] = request_token
     raise web.seeother(url)
Ejemplo n.º 6
0
 def GET(self, authType):
     if authType.lower() != 'pocket':
         return 'Auth Type(%s) Unsupported!' % authType
         
     user = self.getcurrentuser()
     reUrl = web.input().get('redirect')
     if not reUrl:
         reUrl = '/advsettings'
         
     pocket = Pocket(POCKET_CONSUMER_KEY)
     request_token = main.session.get('pocket_request_token', '')
     try:
         resp = pocket.get_access_token(request_token)
         user.pocket_access_token = resp.get('access_token', '')
         user.pocket_acc_token_hash = hashlib.md5(user.pocket_access_token).hexdigest()
         user.put()
         return self.render('tipsback.html', 'Success authorized', urltoback='/advarchive', tips=_('Success authorized by Pocket!'))
     except Exception as e:
         user.pocket_access_token = ''
         user.pocket_acc_token_hash = ''
         user.pocket = False
         user.put()
         return self.render('tipsback.html', 'Failed to authorzi', urltoback='/advarchive', 
             tips=_('Failed to request authorization of Pocket!<hr/>See details below:<br/><br/>%s') % str(e))