def Get_blog163(self, model, pushitem, **kwargs): try: form_fields = { "title": htmllib.encoding(stringQ2B(htmllib.encoding(model.title)), 'gb2312'), "content": htmllib.encoding(stringQ2B(htmllib.encoding(model.content)), 'gb2312'), "name": pushitem.username, "password":pushitem.password } form_data = urllib.urlencode(form_fields) result = urlfetch.fetch(url='http://blog.163.com/common/targetgo.s', payload=form_data, method=urlfetch.POST, headers={'Content-Type': 'application/x-www-form-urlencoded'}) if result.status_code == 200: return self.Get_True(model, pushitem) elif result.status_code == 500: logging.error('Push %s returned with status code 500.' % pushitem.pushurl) return False elif result.status_code == 404: logging.error('Error 404: Nothing found at %s.' % pushitem.pushurl) return False except Exception, data: return self.Get_False(model, pushitem, data)
def Get_qzone(self, model, pushitem, **kwargs): try: message = mail.EmailMessage() message.sender = '*****@*****.**' % pushitem.username message.to = '*****@*****.**' % pushitem.username message.body = htmllib.encoding(stringQ2B(htmllib.encoding(model.content)), 'gb2312') message.subject = htmllib.encoding(stringQ2B(htmllib.encoding(model.title)), 'gb2312') message.send() return self.Get_True(model, pushitem) except Exception, data: return self.Get_False(model, pushitem, data)
def verify_checkcode(self): sess = self.session #sess=Session(self,timeout=180) #if not (self.request.cookies.get('comment_user', '')): check_ret = True try: if self.blog.comment_check_type == 1: checkret = self.param('checkret') # 客户端会自动请求刷新验证码 code = sess.pop('code') check_ret = (int(checkret) == code) elif self.blog.comment_check_type == 2: checkret = self.param('checkret') # 客户端会自动请求刷新验证码 icode = sess.pop('icode') check_ret = (int(checkret) == int(icode)) elif self.blog.comment_check_type == 3: import app.gbtools as gb checknum = self.param('checknum') checkret = self.param('checkret') check_ret = eval(checknum)==int(gb.stringQ2B(checkret)) except Exception,e: logging.error(e) check_ret = False
def Get_qq_msgs(self, model, pushitem, **kwargs): """ this method is used to get login to website,and put the content to the micro blog """ try: content = '#%s# %s 详细内容请查看:%s' % (htmllib.encoding(stringQ2B(htmllib.encoding(model.title)), 'utf-8'), htmllib.encoding(stringQ2B(htmllib.encoding(htmllib.Filter_html(model.excerpt))), 'utf-8')[:100], str(model.fullurl)) result = self.send_sina_msgs(pushitem.username, pushitem.password, content) if result: return self.Get_True(model, pushitem) else: return self.Get_False(model, pushitem) except Exception, data: return self.Get_False(model, pushitem, data)
def __Parse_image(self, content): images = htmllib.Parse_images_url(content) if images: try: for image in images: tmpimage = Media.all().filter("oldurl = ", image).get() if tmpimage != None: content = gbtools.stringQ2B(content) content = htmllib.decoding(content).replace(image, tmpimage.PhotoUrl()) except Exception, data: logging.info(data)
def __Parse_image(self, content): images = htmllib.Parse_images_url(content) if images: try: for image in images: tmpimage = Media.all().filter('oldurl = ', image).get() if tmpimage != None: content = gbtools.stringQ2B(content) content = htmllib.decoding(content).replace( image, tmpimage.PhotoUrl()) except Exception, data: logging.info(data)
def __Parse_image(self, entry): images = htmllib.Parse_images_url(entry.content) content = '' if images: try: for image in images: tmpimage = Media.all().filter('oldurl = ', image).get() if tmpimage != None: content = gbtools.stringQ2B(content) content = htmllib.decoding(entry.content).replace(image, tmpimage.PhotoUrl()) else: pass except Exception, data: return None return content
def __Parse_image(self, entry): images = htmllib.Parse_images_url(entry.content) content = '' if images: try: for image in images: tmpimage = Media.all().filter('oldurl = ', image).get() if tmpimage != None: content = gbtools.stringQ2B(content) content = htmllib.decoding(entry.content).replace( image, tmpimage.PhotoUrl()) else: pass except Exception, data: return None return content
def post(self,slug=None): useajax=self.param('useajax')=='1' ismobile=self.paramint('ismobile')==1 #if not self.is_login: # if useajax: # self.write(json.dumps((False,-102,_('You must login before comment.')),ensure_ascii = False)) # else: # self.error(-102,_('You must login before comment .')) # return if not self.is_login: sess=Session(self,timeout=180) try: check_ret=True if self.blog.comment_check_type==1: checkret=self.param('checkret') check_ret=(int(checkret) == sess['code']) elif self.blog.comment_check_type==2: checkret=self.param('checkret') check_ret=(str(checkret) == sess['icode']) elif self.blog.comment_check_type ==3: import app.gbtools as gb checknum=self.param('checknum') checkret=self.param('checkret') check_ret=eval(checknum)==int(gb.stringQ2B( checkret)) if not check_ret: if useajax: self.write(json.dumps((False,-102,_('Your check code is invalid .')),ensure_ascii = False)) else: self.error(-102,_('Your check code is invalid .')) return except Exception,e: if useajax: self.write(json.dumps((False,-102,_('Your check code is invalid .')+unicode(e)),ensure_ascii = False)) else: self.error(-102,_('Your check code is invalid .')) return sess.invalidate()
def post(self, slug=None): useajax = self.param('useajax') == '1' name = self.param('author') email = self.param('email') url = self.param('url') key = self.param('key') content = self.param('comment') parent_id = self.paramint('parentid', 0) reply_notify_mail = self.parambool('reply_notify_mail') sess = Session(self, timeout=180) if not self.is_login: #if not (self.request.cookies.get('comment_user', '')): try: check_ret = True if g_blog.comment_check_type in (1, 2): checkret = self.param('checkret') check_ret = (int(checkret) == sess['code']) elif g_blog.comment_check_type == 3: import app.gbtools as gb checknum = self.param('checknum') checkret = self.param('checkret') check_ret = eval(checknum) == int(gb.stringQ2B(checkret)) if not check_ret: if useajax: self.write( simplejson.dumps( (False, -102, _('Your check code is invalid .')), ensure_ascii=False)) else: self.error(-102, _('Your check code is invalid .')) return except: if useajax: self.write( simplejson.dumps( (False, -102, _('Your check code is invalid .')), ensure_ascii=False)) else: self.error(-102, _('Your check code is invalid .')) return sess.invalidate() content = content.replace('\n', '<br />') content = myfilter.do_filter(content) name = cgi.escape(name)[:20] url = cgi.escape(url)[:100] if not (name and email and content): if useajax: self.write( simplejson.dumps( (False, -101, _('Please input name, email and comment .')))) else: self.error(-101, _('Please input name, email and comment .')) else: comment = Comment(author=name, content=content, email=email, reply_notify_mail=reply_notify_mail, entry=Entry.get(key)) if url: try: if not url.lower().startswith(('http://', 'https://')): url = 'http://' + url comment.weburl = url except: comment.weburl = None #name=name.decode('utf8').encode('gb2312') info_str = '#@#'.join( [urlencode(name), urlencode(email), urlencode(url)]) #info_str='#@#'.join([name,email,url.encode('utf8')]) cookiestr = 'comment_user=%s;expires=%s;path=/;' % (info_str, ( datetime.now() + timedelta(days=100)).strftime("%a, %d-%b-%Y %H:%M:%S GMT")) comment.ip = self.request.remote_addr if parent_id: comment.parent = Comment.get_by_id(parent_id) comment.no = comment.entry.commentcount + 1 try: comment.save() memcache.delete("/" + comment.entry.link) self.response.headers.add_header('Set-Cookie', cookiestr) if useajax: comment_c = self.get_render('comment', {'comment': comment}) self.write( simplejson.dumps((True, comment_c.decode('utf8')), ensure_ascii=False)) else: self.redirect(self.referer + "#comment-" + str(comment.key().id())) comment.entry.removecache() memcache.delete("/feed/comments") except: if useajax: self.write( simplejson.dumps( (False, -102, _('Comment not allowed.')))) else: self.error(-102, _('Comment not allowed .'))
def post(self,slug=None): useajax=self.param('useajax')=='1' name=self.param('author') email=self.param('email') url=self.param('url') key=self.param('key') content=self.param('comment') parent_id=self.paramint('parentid',0) reply_notify_mail=self.parambool('reply_notify_mail') sess=Session(self,timeout=180) if not self.is_login: #if not (self.request.cookies.get('comment_user', '')): try: check_ret=True if g_blog.comment_check_type in (1,2) : checkret=self.param('checkret') logging.info('______'+checkret) check_ret=(int(checkret) == sess['code']) elif g_blog.comment_check_type ==3: import app.gbtools as gb checknum=self.param('checknum') checkret=self.param('checkret') check_ret=eval(checknum)==int(gb.stringQ2B( checkret)) if not check_ret: if useajax: self.write(simplejson.dumps((False,-102,_('Your check code is invalid .')))) else: self.error(-102,_('Your check code is invalid .')) return except: if useajax: self.write(simplejson.dumps((False,-102,_('Your check code is invalid .')))) else: self.error(-102,_('Your check code is invalid .')) return sess.invalidate() content=content.replace('\n','<br>') content=myfilter.do_filter(content) name=cgi.escape(name)[:20] url=cgi.escape(url)[:100] if not (name and email and content): if useajax: self.write(simplejson.dumps((False,-101,_('Please input name, email and comment .')))) else: self.error(-101,_('Please input name, email and comment .')) else: comment=Comment(author=name, content=content, email=email, reply_notify_mail=reply_notify_mail, entry=Entry.get(key)) if url: try: comment.weburl=url except: comment.weburl=None #name=name.decode('utf8').encode('gb2312') info_str='#@#'.join([urlencode(name),urlencode(email),urlencode(url)]) #info_str='#@#'.join([name,email,url.encode('utf8')]) cookiestr='comment_user=%s;expires=%s;domain=%s;path=/'%( info_str, (datetime.now()+timedelta(days=100)).strftime("%a, %d-%b-%Y %H:%M:%S GMT"), '' ) comment.ip=self.request.remote_addr if parent_id: comment.parent=Comment.get_by_id(parent_id) try: comment.save() memcache.delete("/"+comment.entry.link) self.response.headers.add_header( 'Set-Cookie', cookiestr) if useajax: comment_c=self.get_render('comment',{'comment':comment}) self.write(simplejson.dumps((True,comment_c.decode('utf8')))) else: self.redirect(self.referer+"#comment-"+str(comment.key().id())) comment.entry.removecache() memcache.delete("/feed/comments") except: if useajax: self.write(simplejson.dumps((False,-102,_('Comment not allowed.')))) else: self.error(-102,_('Comment not allowed .'))
def post(self,slug=None): useajax=self.param('useajax')=='1' name=self.param('author') email=self.param('email') url=self.param('url') key=self.param('key') content=self.param('comment') parent_id=self.paramint('parentid',0) reply_notify_mail=self.parambool('reply_notify_mail') sess=Session(self,timeout=180) if not self.is_login: #if not (self.request.cookies.get('comment_user', '')): try: check_ret=True if g_blog.comment_check_type in (1,2) : checkret=self.param('checkret') check_ret=(int(checkret) == sess['code']) elif g_blog.comment_check_type ==3: import app.gbtools as gb checknum=self.param('checknum') checkret=self.param('checkret') check_ret=eval(checknum)==int(gb.stringQ2B( checkret)) elif g_blog.comment_check_type == 4:#reCAPTCHA, probably not working in China mainland ip = self.request.remote_addr private_key = "6Leox8YSAAAAAGJ734ttj4OYojDiCcsb1tcDBarA" resp = self.param('checkret') chalg = self.param('challenge') import urllib import urllib2 params = urllib.urlencode({ 'privatekey': private_key, 'remoteip' : ip, 'challenge' : chalg, 'response' : resp }) request = urllib2.Request( url = "http://www.google.com/recaptcha/api/verify", data = params, headers = { "Content-type": "application/x-www-form-urlencoded" } ) httpresp = urllib2.urlopen(request) return_values = httpresp.read().splitlines(); check_ret = (return_values[0] == "true") if not check_ret: if useajax: self.write(simplejson.dumps((False,-102,_('Your check code is invalid .')),ensure_ascii = False)) else: self.error(-102,_('Your check code is invalid .')) return except Exception: logging.exception('Error when checking CAPTCHA') #Assume the captcha is right, which is less confusing. TODO: send admin an email to notify this event ''' if useajax: self.write(simplejson.dumps((False,-102,_('Your check code is invalid .')),ensure_ascii = False)) else: self.error(-102,_('Your check code is invalid .')) return ''' sess.invalidate() content=content.replace('\n','<br />') content=myfilter.do_filter(content) name=cgi.escape(name)[:20] url=cgi.escape(url)[:100] if not (name and email and content): if useajax: self.write(simplejson.dumps((False,-101,_('Please input name, email and comment .')))) else: self.error(-101,_('Please input name, email and comment .')) else: comment=Comment(author=name, content=content, email=email, reply_notify_mail=reply_notify_mail, entry=Entry.get(key)) if url: try: if not url.startswith(('http://','https://')): url = 'http://' + url comment.weburl=url except: comment.weburl=None #name=name.decode('utf8').encode('gb2312') info_str='#@#'.join([urlencode(name),urlencode(email),urlencode(url)]) #info_str='#@#'.join([name,email,url.encode('utf8')]) cookiestr='comment_user=%s;expires=%s;domain=%s;path=/'%( info_str, (datetime.now()+timedelta(days=100)).strftime("%a, %d-%b-%Y %H:%M:%S GMT"), '' ) comment.ip=self.request.remote_addr if parent_id: comment.parent=Comment.get_by_id(parent_id) comment.no=comment.entry.commentcount+1 try: comment.save() #take care of cache self.response.headers.add_header( 'Set-Cookie', cookiestr) if useajax: comment_c=self.get_render('comment',{'comment':comment}) self.write(simplejson.dumps((True,comment_c.decode('utf8')),ensure_ascii = False)) else: self.redirect(self.referer+"#comment-"+str(comment.key().id())) comment.entry.removecache() memcache.delete("/feed/comments") except: if useajax: self.write(simplejson.dumps((False,-102,_('Comment not allowed.')))) else: self.error(-102,_('Comment not allowed .'))
def post(self,slug=None): useajax=self.param('useajax')=='1' ## if self.is_admin: ## name=self.blog.author ## email=self.login_user.email() ## url=self.blog.baseurl ## else: name=self.param('author') email=self.param('email') url=self.param('url') key=self.param('key') content=self.param('comment') checknum=self.param('checknum') checkret=self.param('checkret') ## if useajax: ## name=urldecode(name) ## email=urldecode(email) ## url=urldecode(url) ## key=urldecode(key) ## content=urldecode(content) ## checknum=urldecode(checknum) ## checkret=urldecode(checkret) if not self.is_login: if not (self.request.cookies.get('comment_user', '')): try: import app.gbtools as gb if eval(checknum)<>int(gb.stringQ2B( checkret)): if useajax: self.write(simplejson.dumps((False,-102,_('Your check code is invalid .')))) else: self.error(-102,_('Your check code is invalid .')) return except: if useajax: self.write(simplejson.dumps((False,-102,_('Your check code is invalid .')))) else: self.error(-102,_('Your check code is invalid .')) return content=content.replace('\n','<br>') content=myfilter.do_filter(content) name=cgi.escape(name)[:20] url=cgi.escape(url)[:100] if not (name and email and content): if useajax: self.write(simplejson.dumps((False,-101,_('Please input name, email and comment .')))) else: self.error(-101,_('Please input name, email and comment .')) else: comment=Comment(author=name, content=content, email=email, entry=Entry.get(key)) if url: try: comment.weburl=url except: comment.weburl='http://'+url #name=name.decode('utf8').encode('gb2312') info_str='#@#'.join([urlencode(name),urlencode(email),urlencode(url)]) logging.info("info:"+info_str) #info_str='#@#'.join([name,email,url.encode('utf8')]) cookiestr='comment_user=%s;expires=%s;domain=%s;path=/'%( info_str, (datetime.now()+timedelta(days=100)).strftime("%a, %d-%b-%Y %H:%M:%S GMT"), '' ) comment.save() memcache.delete("/"+comment.entry.link) self.response.headers.add_header( 'Set-Cookie', cookiestr) if useajax: comment_c=self.get_render('comment',{'comment':comment}) self.write(simplejson.dumps((True,comment_c.decode('utf8')))) else: self.redirect(self.referer)
def post(self, slug=None): useajax = self.param("useajax") == "1" name = self.param("author") email = self.param("email") url = self.param("url") key = self.param("key") content = self.param("comment") parent_id = self.paramint("parentid", 0) reply_notify_mail = self.parambool("reply_notify_mail") sess = Session(self, timeout=180) if not self.is_login: # if not (self.request.cookies.get('comment_user', '')): try: check_ret = True if g_blog.comment_check_type in (1, 2): checkret = self.param("checkret") check_ret = int(checkret) == sess["code"] elif g_blog.comment_check_type == 3: import app.gbtools as gb checknum = self.param("checknum") checkret = self.param("checkret") check_ret = eval(checknum) == int(gb.stringQ2B(checkret)) if not check_ret: if useajax: self.write( simplejson.dumps((False, -102, _("Your check code is invalid .")), ensure_ascii=False) ) else: self.error(-102, _("Your check code is invalid .")) return except: if useajax: self.write(simplejson.dumps((False, -102, _("Your check code is invalid .")), ensure_ascii=False)) else: self.error(-102, _("Your check code is invalid .")) return sess.invalidate() content = content.replace("\n", "<br />") content = myfilter.do_filter(content) name = cgi.escape(name)[:20] url = cgi.escape(url)[:100] if not (name and email and content): if useajax: self.write(simplejson.dumps((False, -101, _("Please input name, email and comment .")))) else: self.error(-101, _("Please input name, email and comment .")) else: comment = Comment( author=name, content=content, email=email, reply_notify_mail=reply_notify_mail, entry=Entry.get(key) ) if url: try: if not url.startswith(("http://", "https://")): url = "http://" + url comment.weburl = url except: comment.weburl = None # name=name.decode('utf8').encode('gb2312') info_str = "#@#".join([urlencode(name), urlencode(email), urlencode(url)]) # info_str='#@#'.join([name,email,url.encode('utf8')]) cookiestr = "comment_user=%s;expires=%s;domain=%s;path=/" % ( info_str, (datetime.now() + timedelta(days=100)).strftime("%a, %d-%b-%Y %H:%M:%S GMT"), "", ) comment.ip = self.request.remote_addr if parent_id: comment.parent = Comment.get_by_id(parent_id) comment.no = comment.entry.commentcount + 1 try: comment.save() memcache.delete("/" + comment.entry.link) self.response.headers.add_header("Set-Cookie", cookiestr) if useajax: comment_c = self.get_render("comment", {"comment": comment}) self.write(simplejson.dumps((True, comment_c.decode("utf8")), ensure_ascii=False)) else: self.redirect(self.referer + "#comment-" + str(comment.key().id())) comment.entry.removecache() memcache.delete("/feed/comments") except: if useajax: self.write(simplejson.dumps((False, -102, _("Comment not allowed.")))) else: self.error(-102, _("Comment not allowed ."))
def post(self, slug=None): useajax = self.param("useajax") == "1" ## if self.is_admin: ## name=self.blog.author ## email=self.login_user.email() ## url=self.blog.baseurl ## else: name = self.param("author") email = self.param("email") url = self.param("url") key = self.param("key") content = self.param("comment") checknum = self.param("checknum") checkret = self.param("checkret") ## if useajax: ## name=urldecode(name) ## email=urldecode(email) ## url=urldecode(url) ## key=urldecode(key) ## content=urldecode(content) ## checknum=urldecode(checknum) ## checkret=urldecode(checkret) if not self.is_login: if not (self.request.cookies.get("comment_user", "")): try: import app.gbtools as gb if eval(checknum) <> int(gb.stringQ2B(checkret)): if useajax: self.write(simplejson.dumps((False, -102, _("Your check code is invalid .")))) else: self.error(-102, _("Your check code is invalid .")) return except: if useajax: self.write(simplejson.dumps((False, -102, _("Your check code is invalid .")))) else: self.error(-102, _("Your check code is invalid .")) return content = content.replace("\n", "<br>") content = myfilter.do_filter(content) name = cgi.escape(name)[:20] url = cgi.escape(url)[:100] if not (name and email and content): if useajax: self.write(simplejson.dumps((False, -101, _("Please input name, email and comment .")))) else: self.error(-101, _("Please input name, email and comment .")) else: comment = Comment(author=name, content=content, email=email, entry=Entry.get(key)) if url: try: comment.weburl = url except: comment.weburl = "http://" + url # name=name.decode('utf8').encode('gb2312') info_str = "#@#".join([urlencode(name), urlencode(email), urlencode(url)]) logging.info("info:" + info_str) # info_str='#@#'.join([name,email,url.encode('utf8')]) cookiestr = "comment_user=%s;expires=%s;domain=%s;path=/" % ( info_str, (datetime.now() + timedelta(days=100)).strftime("%a, %d-%b-%Y %H:%M:%S GMT"), "", ) comment.save() memcache.delete("/" + comment.entry.link) self.response.headers.add_header("Set-Cookie", cookiestr) if useajax: comment_c = self.get_render("comment", {"comment": comment}) self.write(simplejson.dumps((True, comment_c.decode("utf8")))) else: self.redirect(self.referer + "#comment-" + str(comment.key().id()))