def get_diff_str(*args): mpost = MPost() mposthist = MPostHist() diff_str = '' for key in router_post.keys(): recent_posts = mpost.query_recent_edited(tools.timestamp() - time_limit, kind=key) for recent_post in recent_posts: hist_rec = mposthist.get_last(recent_post.uid) if hist_rec: raw_title = hist_rec.title new_title = recent_post.title infobox = diff_table(raw_title, new_title) # infobox = test[start:end] + '</table>' # if ('diff_add' in infobox) or ('diff_chg' in infobox) or ('diff_sub' in infobox): diff_str = diff_str + '<h2 style="color:red; font-size:larger; font-weight:70;">TITLE: {0}</h2>'.format( recent_post.title) + infobox infobox = diff_table(hist_rec.cnt_md, recent_post.cnt_md) diff_str = diff_str + '<h3>CONTENT:{0}</h3>'.format( recent_post.title) + infobox + '</hr>' else: continue return diff_str
def __get_diff_recent(): ''' Generate the difference of posts. recently. ''' diff_str = '' for key in router_post: recent_posts = MPost.query_recent_edited(tools.timestamp() - TIME_LIMIT, kind=key) for recent_post in recent_posts: hist_rec = MPostHist.get_last(recent_post.uid) if hist_rec: raw_title = hist_rec.title new_title = recent_post.title infobox = diff_table(raw_title, new_title) diff_str = diff_str + ''' <h2 style="color:red;font-size:larger;font-weight:70;">TITLE: {0}</h2> '''.format(recent_post.title) + infobox infobox = diff_table(hist_rec.cnt_md, recent_post.cnt_md) diff_str = diff_str + '<h3>CONTENT:{0}</h3>'.format( recent_post.title) + infobox + '</hr>' else: continue return diff_str
def view(self, uid): postinfo = self.mpost.get_by_id(uid) if postinfo: pass else: return hist_recs = self.mposthist.query_by_postid(uid, limit=5) html_diff_arr = [] for hist_rec in hist_recs: if hist_rec: infobox = diff_table(hist_rec.cnt_md, postinfo.cnt_md) else: infobox = '' html_diff_arr.append({ 'hist_uid': hist_rec.uid, 'html_diff': infobox }) self.render( 'man_post/post_man_view.html', userinfo=self.userinfo, unescape=tornado.escape.xhtml_unescape, view=postinfo, postinfo=postinfo, html_diff_arr=html_diff_arr, router=router_post[postinfo.kind], )
def view(self, uid): ''' View the wiki with hisotical infos. ''' postinfo = MWiki.get_by_uid(uid) if postinfo: pass else: return hist_recs = MWikiHist.query_by_wikiid(uid, limit=5) html_diff_arr = [] for hist_rec in hist_recs: if hist_rec: infobox = diff_table(hist_rec.cnt_md, postinfo.cnt_md) hist_user = hist_rec.user_name else: infobox = '' html_diff_arr.append({ 'hist_uid': hist_rec.uid, 'html_diff': infobox, 'hist_user': hist_user }) self.render( 'man_info/wiki_man_view.html', userinfo=self.userinfo, unescape=tornado.escape.xhtml_unescape, view=postinfo, # Deprecated postinfo=postinfo, html_diff_arr=html_diff_arr)
def view(self, uid): postinfo = self.mpost.get_by_id(uid) if postinfo: pass else: return hist_recs = self.mposthist.query_by_wikiid(uid, limit=5) html_diff_arr = [] for hist_rec in hist_recs: if hist_rec: infobox = diff_table(hist_rec.cnt_md, postinfo.cnt_md) else: infobox = '' html_diff_arr.append({ 'hist_uid': hist_rec.uid, 'html_diff': infobox }) self.render( '{0}/wiki_man_view.html'.format(self.tmpl_dir), userinfo=self.userinfo, unescape=tornado.escape.xhtml_escape, view=postinfo, # Deprecated postinfo=postinfo, html_diff_arr=html_diff_arr)
def view(self, uid): postinfo = MPost.get_by_uid(uid) if postinfo: pass else: return hist_recs = MPostHist.query_by_postid(uid, limit=5) html_diff_arr = [] for hist_rec in hist_recs: if hist_rec: infobox = diff_table(hist_rec.cnt_md, postinfo.cnt_md) hist_user = hist_rec.user_name else: infobox = '' hist_user = '' html_diff_arr.append({ 'hist_uid': hist_rec.uid, 'html_diff': infobox, 'hist_user': hist_user }) self.render('man_info/post_man_view.html', userinfo=self.userinfo, view=postinfo, postinfo=postinfo, html_diff_arr=html_diff_arr, router=router_post[postinfo.kind])
def view(self, uid): ''' View the wiki with hisotical infos. ''' postinfo = MWiki.get_by_uid(uid) if postinfo: pass else: return hist_recs = MWikiHist.query_by_wikiid(uid, limit=5) html_diff_arr = [] if hist_recs: for hist_rec in hist_recs: infobox = diff_table(hist_rec.cnt_md, postinfo.cnt_md) hist_user = hist_rec.user_name hist_time = hist_rec.time_update hist_words_num = len((hist_rec.cnt_md).strip()) post_words_num = len((postinfo.cnt_md).strip()) up_words_num = post_words_num - hist_words_num html_diff_arr.append( {'hist_uid': hist_rec.uid, 'html_diff': infobox, 'hist_user': hist_user, 'hist_time': hist_time, 'up_words_num': up_words_num} ) kwd = {} self.render('man_info/wiki_man_view.html', userinfo=self.userinfo, postinfo=postinfo, html_diff_arr=html_diff_arr, kwd=kwd) else: self.redirect('/{0}/{1}'.format(router_post[postinfo.kind], postinfo.uid))
def view(self, uid): ''' View the wiki with hisotical infos. ''' postinfo = MWiki.get_by_uid(uid) if postinfo: pass else: return hist_recs = MWikiHist.query_by_wikiid(uid, limit=5) html_diff_arr = [] for hist_rec in hist_recs: if hist_rec: infobox = diff_table(hist_rec.cnt_md, postinfo.cnt_md) hist_user = hist_rec.user_name hist_time = hist_rec.time_update hist_words_num = len((hist_rec.cnt_md).strip()) post_words_num = len((postinfo.cnt_md).strip()) up_words_num = post_words_num - hist_words_num else: infobox = '' hist_user = '' hist_time = '' up_words_num = '' html_diff_arr.append({ 'hist_uid': hist_rec.uid, 'html_diff': infobox, 'hist_user': hist_user, 'hist_time': hist_time, 'up_words_num': up_words_num }) self.render( 'man_info/wiki_man_view.html', userinfo=self.userinfo, view=postinfo, # Deprecated postinfo=postinfo, html_diff_arr=html_diff_arr)
def view(self, uid): postinfo = MPost.get_by_uid(uid) if postinfo: pass else: return hist_recs = MPostHist.query_by_postid(uid, limit=5) html_diff_arr = [] for hist_rec in hist_recs: if hist_rec: infobox = diff_table(hist_rec.cnt_md, postinfo.cnt_md) hist_user = hist_rec.user_name hist_time = hist_rec.time_update hist_words_num = len((hist_rec.cnt_md).strip()) post_words_num = len((postinfo.cnt_md).strip()) up_words_num = post_words_num - hist_words_num else: infobox = '' hist_user = '' hist_time = '' up_words_num = '' html_diff_arr.append({ 'hist_uid': hist_rec.uid, 'html_diff': infobox, 'hist_user': hist_user, 'hist_time': hist_time, 'up_words_num': up_words_num }) kwd = {} self.render('man_info/post_man_view.html', userinfo=self.userinfo, view=postinfo, postinfo=postinfo, html_diff_arr=html_diff_arr, router=router_post[postinfo.kind], kwd=kwd)
def run_edit_diff(): email_cnt = '''<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> table.diff {font-family:Courier; border:medium;} .diff_header {background-color:#e0e0e0} td.diff_header {text-align:right} .diff_next {background-color:#c0c0c0} .diff_add {background-color:#aaffaa} .diff_chg {background-color:#ffff77} .diff_sub {background-color:#ffaaaa} </style></head><body>''' idx = 1 email_cnt = email_cnt + '<table border=1>' mpost = MPost() mposthist = MPostHist() recent_posts = mpost.query_recent_edited(tools.timestamp() - 24 * 60 * 60) for recent_post in recent_posts: hist_rec = mposthist.get_last(recent_post.uid) if hist_rec: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(site_url, 'post', recent_post.uid + '.html')) email_cnt = email_cnt + foo_str else: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(site_url, 'post', recent_post.uid + '.html')) email_cnt = email_cnt + foo_str idx = idx + 1 recent_posts = mpost.query_recent_edited(tools.timestamp() - 24 * 60 * 60, kind='2') for recent_post in recent_posts: hist_rec = mposthist.get_last(recent_post.uid) if hist_rec: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(site_url, router_post['2'], recent_post.uid)) email_cnt = email_cnt + foo_str else: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(site_url, router_post['2'], recent_post.uid)) email_cnt = email_cnt + foo_str idx = idx + 1 mpost = MWiki() mposthist = MWikiHist() recent_posts = mpost.query_recent_edited(tools.timestamp() - 24 * 60 * 60) for recent_post in recent_posts: hist_rec = mposthist.get_last(recent_post.uid) if hist_rec: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(site_url, 'wiki', recent_post.title)) email_cnt = email_cnt + foo_str else: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(site_url, 'wiki', recent_post.title)) email_cnt = email_cnt + foo_str idx = idx + 1 recent_posts = mpost.query_recent_edited(tools.timestamp() - 24 * 60 * 60, kind='2') for recent_post in recent_posts: hist_rec = mposthist.get_last(recent_post.uid) if hist_rec: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(site_url, 'page', recent_post.uid + '.html')) email_cnt = email_cnt + foo_str else: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(site_url, 'page', recent_post.uid + '.html')) email_cnt = email_cnt + foo_str idx = idx + 1 email_cnt = email_cnt + '</table>' mpost = MPost() mposthist = MPostHist() diff_str = '' ###################################################### recent_posts = mpost.query_recent_edited(tools.timestamp() - 24 * 60 * 60) for recent_post in recent_posts: hist_rec = mposthist.get_last(recent_post.uid) if hist_rec: print('=' * 10) print(recent_post.title) raw_title = hist_rec.title new_title = recent_post.title infobox = diff_table(raw_title, new_title) # if len(test) > 1: # start = test.find('<table class="diff"') # 起点记录查询位置 # end = test.find('</table>') # infobox = test[start:end] + '</table>' # if ('diff_add' in infobox) or ('diff_chg' in infobox) or ('diff_sub' in infobox): diff_str = diff_str + '<h2 style="color:red; font-size:larger; font-weight:70;">TITLE: {0}</h2>'.format( recent_post.title) + infobox test = diff_table(hist_rec.cnt_md, recent_post.cnt_md) print(test) # if len(test) >1 : # start = test.find('<table class="diff"') # 起点记录查询位置 # end = test.find('</table>') # infobox = test[start:end] + '</table>' # if ('diff_add' in infobox) or ('diff_chg' in infobox) or ('diff_sub' in infobox): diff_str = diff_str + '<h3>CONTENT</h3>'.format( recent_post.title) + test + '</hr>' else: continue ###################################################### recent_posts = mpost.query_recent_edited(tools.timestamp() - 24 * 60 * 60, kind='2') for recent_post in recent_posts: hist_rec = mposthist.get_last(recent_post.uid) if hist_rec: print('=' * 10) print(recent_post.title) raw_title = hist_rec.title new_title = recent_post.title infobox = diff_table(raw_title, new_title) # infobox = test[start:end] + '</table>' # if ('diff_add' in infobox) or ('diff_chg' in infobox) or ('diff_sub' in infobox): diff_str = diff_str + '<h2 style="color:red; font-size:larger; font-weight:70;">TITLE: {0}</h2>'.format( recent_post.title) + infobox infobox = diff_table(hist_rec.cnt_md, recent_post.cnt_md) diff_str = diff_str + '<h3>CONTENT</h3>'.format( recent_post.title) + infobox + '</hr>' else: continue ########################################################### if len(diff_str) < 20000: email_cnt = email_cnt + diff_str email_cnt = email_cnt + '''<table class="diff" summary="Legends"> <tr> <th colspan="2"> Legends </th> </tr> <tr> <td> <table border="" summary="Colors"> <tr><th> Colors </th> </tr> <tr><td class="diff_add"> Added </td></tr> <tr><td class="diff_chg">Changed</td> </tr> <tr><td class="diff_sub">Deleted</td> </tr> </table></td> <td> <table border="" summary="Links"> <tr><th colspan="2"> Links </th> </tr> <tr><td>(f)irst change</td> </tr> <tr><td>(n)ext change</td> </tr> <tr><td>(t)op</td> </tr> </table></td> </tr> </table></body>''' # print (email_cnt) print('edit diff count:', idx) if idx > 1: send_mail(post_emails, "{0}|{1}|{2}".format(smtp_cfg['name'], '文档更新情况', datestr), email_cnt)
def run_edit_diff(): email_cnt = '''<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> table.diff {font-family:Courier; border:medium;} .diff_header {background-color:#e0e0e0} td.diff_header {text-align:right} .diff_next {background-color:#c0c0c0} .diff_add {background-color:#aaffaa} .diff_chg {background-color:#ffff77} .diff_sub {background-color:#ffaaaa} </style></head><body>''' idx = 1 email_cnt = email_cnt + '<table border=1>' mpost = MPost() mposthist = MPostHist() for key in router_post.keys(): recent_posts = mpost.query_recent_edited(tools.timestamp() - time_limit, kind=key) for recent_post in recent_posts: hist_rec = mposthist.get_last(recent_post.uid) if hist_rec: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(site_url, router_post[key], recent_post.uid)) email_cnt = email_cnt + foo_str else: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(site_url, router_post[key], recent_post.uid)) email_cnt = email_cnt + foo_str idx = idx + 1 ## wiki mpost = MWiki() mposthist = MWikiHist() recent_posts = mpost.query_recent_edited(tools.timestamp() - time_limit) for recent_post in recent_posts: hist_rec = mposthist.get_last(recent_post.uid) if hist_rec: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(site_url, 'wiki', recent_post.title)) email_cnt = email_cnt + foo_str else: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(site_url, 'wiki', recent_post.title)) email_cnt = email_cnt + foo_str idx = idx + 1 ## page. recent_posts = mpost.query_recent_edited(tools.timestamp() - time_limit, kind='2') for recent_post in recent_posts: hist_rec = mposthist.get_last(recent_post.uid) if hist_rec: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format(idx, recent_post.user_name, recent_post.title, os.path.join(site_url, 'page', recent_post.uid)) email_cnt = email_cnt + foo_str else: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format(idx, recent_post.user_name, recent_post.title, os.path.join(site_url, 'page', recent_post.uid)) email_cnt = email_cnt + foo_str idx = idx + 1 email_cnt = email_cnt + '</table>' mpost = MPost() mposthist = MPostHist() diff_str = '' ###################################################### ###################################################### for key in router_post.keys(): recent_posts = mpost.query_recent_edited(tools.timestamp() - time_limit, kind=key) for recent_post in recent_posts: hist_rec = mposthist.get_last(recent_post.uid) if hist_rec: print('=' * 10) print(recent_post.title) raw_title = hist_rec.title new_title = recent_post.title infobox = diff_table(raw_title, new_title) # infobox = test[start:end] + '</table>' # if ('diff_add' in infobox) or ('diff_chg' in infobox) or ('diff_sub' in infobox): diff_str = diff_str + '<h2 style="color:red; font-size:larger; font-weight:70;">TITLE: {0}</h2>'.format( recent_post.title) + infobox infobox = diff_table(hist_rec.cnt_md, recent_post.cnt_md) diff_str = diff_str + '<h3>CONTENT</h3>'.format( recent_post.title) + infobox + '</hr>' else: continue ########################################################### if len(diff_str) < 20000: email_cnt = email_cnt + diff_str email_cnt = email_cnt + '''</body></html>''' # print (email_cnt) print('edit diff count:', idx) if idx > 1: send_mail(post_emails, "{0}|{1}|{2}".format(smtp_cfg['name'], '文档更新情况', datestr), email_cnt)