def SaveToInstapaper(self, user, action, orgUrl): 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.instapaper_username or not user.instapaper_password: info = T_INFO % ('No authorize info', 'Instapaper username and password have to provided fistly!<br/>Please fill them in your KindleEar application.') return info.encode('utf-8') title = web.input().get('t', '') name = web.input().get("n", '') if user.instapaper_username != name: info = T_INFO % ('Action rejected', 'Username not match!<br/>KindleEar refuse to execute your command.') return info.encode('utf-8') opener = URLOpener() password = ke_decrypt(user.instapaper_password, user.secret_key or '') apiParameters = {'username': user.instapaper_username, 'password':password, 'title':title.encode('utf-8'), 'selection':'KindleEar', 'url':orgUrl} ret = opener.open(INSTAPAPER_API_ADD_URL, data=apiParameters) if ret.status_code in (200, 201): info = _("'%s'<br/><br/>Saved to your Instapaper account.") % title info += '<br/><p style="text-align:right;color:red;">by KindleEar </p>' info = T_INFO % ('Saved to Instapaper', info) elif ret.status_code == 403: info = _("Failed save to Instapaper<br/>'%s'<br/><br/>Reason : Invalid username or password.") % title info += '<br/><p style="text-align:right;color:red;">by KindleEar </p>' info = T_INFO % ('Failed to save', info) else: info = _("Failed save to Instapaper<br/>'%s'<br/><br/>Reason : Unknown(%d).") % (title, ret.status_code) info += '<br/><p style="text-align:right;color:red;">by KindleEar </p>' info = T_INFO % ('Failed to save', info) return info.encode('utf-8')
def password(self): return ke_decrypt(self.encrypted_pwd, self.user.secret_key)