Ejemplo n.º 1
0
def do_wiki():
    print('==============================')
    print('For Wiki ... ')
    from torcms.model.wiki_model import MWiki
    mwiki = MWiki()
    #
    from torcms.model.page_model import MPage
    mpage = MPage()

    from model_ent.wiki_model import MWiki as OldWiki
    from model_ent.page_model import MPage as OldPage
    oldwiki = OldWiki()
    oldpage = OldPage()

    print('got it')

    abc = oldwiki.query_all(limit_num=2000)

    ded = oldpage.query_all()
    for rec in oldwiki.query_all(limit_num=20000):
        post_data = {
            "uid": '_' + ''.join(rec.uid.split('-')),
            "title": rec.title,
            "date": rec.date,
            "time_create": rec.time_create,
            "user_name": rec.user_name,
            "time_update": rec.time_update,
            "view_count": rec.view_count,
            "cnt_md": unescape(rec.cnt_md),
            "cnt_html": rec.cnt_html,
            "kind": '1',
        }
        # print(rec.title)
        mwiki.insert_data(post_data)

    for rec in ded:
        print(rec.slug)
        post_data = {
            "uid": rec.slug,
            "title": rec.title,
            "date": rec.date,
            "time_create": rec.time_create,
            "user_name": '',
            "time_update": rec.time_update,
            "view_count": rec.view_count,
            "cnt_md": unescape(rec.cnt_md),
            "cnt_html": rec.cnt_html,
            "kind": '2',
        }
        # print(rec.title)
        mwiki.insert_data(post_data)

    print('QED')
Ejemplo n.º 2
0
def do_for_wiki(writer, rand=True, doc_type=''):
    mpost = MWiki()
    if rand:
        recs = mpost.query_random(50, )
    else:
        recs = mpost.query_recent(50, )

    print(recs.count())
    for rec in recs:
        # sleep(0.1)
        text2 = rec.title + ',' + html2text.html2text(
            tornado.escape.xhtml_unescape(rec.cnt_html))
        # writer.update_document(path=u"/a",content="Replacement for the first document")
        writer.update_document(title=rec.title,
                               catid='0000',
                               type=doc_type,
                               link='/wiki/{0}'.format(rec.title),
                               content=text2)
Ejemplo n.º 3
0
def gen_wiki_map():
    mwiki = MWiki()

    # wiki
    wiki_recs = mwiki.query_all(limit=10000, kind='1')

    with open(sitemap_file, 'a') as fo:
        for rec in wiki_recs:
            url = os.path.join(SITE_CFG['site_url'], 'wiki', rec.title)
            fo.write('{url}\n'.format(url=url))

    ## page.
    page_recs = mwiki.query_all(limit=10000, kind='2')

    with open(sitemap_file, 'a') as fo:
        for rec in page_recs:
            url = os.path.join(SITE_CFG['site_url'], 'page', rec.uid)

            fo.write('{url}\n'.format(url=url))
Ejemplo n.º 4
0
 def initialize(self):
     self.init()
     self.mwiki = MWiki()
     self.mwiki_hist = MWikiHist()
Ejemplo n.º 5
0
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">&nbsp;Added&nbsp;</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)
Ejemplo n.º 6
0
 def setup(self):
     print('setup 方法执行于本类中每条用例之前')
     self.uu = MWiki()
     self.title = 'tyyyitle'
     self.uid = '6985'
Ejemplo n.º 7
0
 def initialize(self):
     self.init()
     self.mpost = MWiki()
     self.mposthist = MWikiHist()
     self.tmpl_dir = 'wiki_man'
Ejemplo n.º 8
0
 def setup(self):
     print('setup 方法执行于本类中每条用例之前')
     self.uu = MWiki()
     self.raw_count = self.uu.get_counts()
     self.page_slug = 'aaa'
     self.uid = tools.get_uuid()
Ejemplo n.º 9
0
def run_edit_diff(*args):
    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_CFG['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_CFG['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_CFG['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_CFG['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_CFG['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_CFG['site_url'], 'page', recent_post.uid))
            email_cnt = email_cnt + foo_str
        idx = idx + 1

    email_cnt = email_cnt + '</table>'

    ###########################################################

    diff_str = get_diff_str()

    if len(diff_str) < 20000:
        email_cnt = email_cnt + diff_str
    email_cnt = email_cnt + '''</body></html>'''

    if idx > 1:
        send_mail(post_emails, "{0}|{1}|{2}".format(SMTP_CFG['name'], '文档更新情况',
                                                    datestr), email_cnt)
Ejemplo n.º 10
0
 def initialize(self):
     self.init()
     self.mpost = MWiki()
     self.mposthist = MWikiHist()
Ejemplo n.º 11
0
 def setup(self):
     print('setup 方法执行于本类中每条用例之前')
     self.uu = MWiki()
     self.raw_count = self.uu.get_counts()
     self.wiki_title = 'lkablkjcdefg'
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
# -*- coding:utf-8 -*-

from torcms.model.info_model import MInfor
from torcms.model.post2catalog_model import MPost2Catalog
from torcms.model.wiki_model import MWiki
from torcms.model.label_model import MLabel
from torcms.model.category_model import MCategory
from config import router_post

mcat = MCategory()
mlabel = MLabel()
mpost = MInfor()
mpost2tag = MPost2Catalog()
mwiki = MWiki()


def run_nocat():
    for key in router_post.keys():
        if key == 'i':
            continue
        post_recs = mpost.query_all(limit_num=50000, kind=key)
        for postinfo in post_recs:
            cat = mpost2tag.get_entry_catalog(postinfo.uid)
            if cat:
                pass
            else:
                print(postinfo.uid)