Ejemplo n.º 1
0
def do_cabpost():
    print('==============================')
    print('For Post ... ')
    from model_ent.post_model import MPost as MPostOld
    mpost_old = MPostOld()

    from torcms.model.post_model import MPost

    mpost = MPost()
    post_recs = mpost_old.query_all()
    for post_rec in post_recs:
        # print(post_rec.uid)

        if post_rec.uid.startswith('m') or post_rec.uid.startswith('g'):
            pass
            # continue
        post_data = {
            'title': post_rec.title,
            'user_name': post_rec.user_name,
            'logo': post_rec.logo,
            'cnt_md': unescape(unescape(post_rec.cnt_md)),
            'keywords': post_rec.keywords,
            'time_create': post_rec.time_create,
            'time_update': post_rec.time_update,
            'kind': '1',
            'valid': 1,
        }
        print(post_rec.uid)
        mpost.add_or_update(buqi_postid(post_rec.uid), post_data)
Ejemplo n.º 2
0
def get_meta(catid, sig):
    meta_base = './static/dataset_list'
    if os.path.exists(meta_base):
        pass
    else:
        return False
    for wroot, wdirs, wfiles in os.walk(meta_base):
        for wdir in wdirs:
            if wdir.lower().endswith(sig):
                ds_base = pathlib.Path(os.path.join(wroot, wdir))

                pp_data = {'logo': '', 'kind': '9'}
                for uu in ds_base.iterdir():
                    if uu.name.endswith('.xlsx'):
                        meta_dic = chuli_meta('u' + sig[2:], uu)
                        pp_data['title'] = meta_dic['title']
                        pp_data['cnt_md'] = meta_dic['anytext']
                        pp_data['user_name'] = 'admin'
                        pp_data['def_cat_uid'] = catid
                        pp_data['def_cat_pid'] = catid[:2] + '00'
                        pp_data['extinfo'] = {}

                        print(uu.name)

                        MPost.add_or_update('u' + sig[2:], pp_data)
                        # print(xlsx.absolute())
                        # MPost.update_misc(post_uid, def_tab_path = xlsx.absolute())
                        kwargsa = {
                            'def_cat_uid': catid,
                            'cat_id': catid,
                        }
                    elif uu.name.startswith('thumbnail_'):
                        pp_data['logo'] = os.path.join(wroot, wdir, uu.name).strip('.')
                update_category('u' + sig[2:], pp_data, kwargsa)
                MPost2Catalog.add_record('u' + sig[2:], catid)
Ejemplo n.º 3
0
def import_meta():
    inws = pathlib.Path('./database/pycsw_meta')
    print(inws)

    for cat_path in inws.iterdir():
        print('x' * 40)
        print(cat_path.name)
        if cat_path.name.lower().endswith('.xlsx'):
            print('////')
            pass
        else:
            continue
        wb = load_workbook(str(cat_path))
        sheets = wb.sheetnames
        for sheet in sheets:
            catid = sheet.split('_')[0]
            catinfo = MCategory.get_by_uid(catid)
            if catinfo:
                pass
            else:
                continue
            ws = wb[sheet]
            rows = ws.max_row
            for i in range(1, rows):
                sig = ws.cell(row=i, column=1).value
                if sig:
                    print(sig)
                    pp_data = get_meta(catid, sig)

                    MPost.add_or_update('u' + sig[2:], pp_data)
                    update_category('u' + sig[2:], pp_data)

                    ws.cell(row=i, column=2).value = pp_data['title']
        # Write a copy with titles.
        wb.save('xx_pycsw_meta.xlsx')
Ejemplo n.º 4
0
def get_meta(catid, sig, cell_cars):
    uid = sig
    meta_base = './script_helper'
    if os.path.exists(meta_base):
        pass
    else:
        return False

    pp_data = {'logo': '', 'kind': 'k'}

    pp_data['title'] = cell_cars[1]
    # pp_data['cnt_md'] = cell_cars[1]

    pp_data['user_name'] = 'admin'
    pp_data['def_cat_uid'] = catid
    pp_data['def_cat_pid'] = catid[:2] + '00'

    pp_data['extinfo'] = {
        # ad_link 不存在则使用 raw_link
        'zlink': cell_cars[3] if cell_cars[3] else cell_cars[4]
    }

    for wroot, wdirs, wfiles in os.walk(meta_base):
        for wdir in wdirs:
            if wdir.lower() == sig:
                ds_base = pathlib.Path(os.path.join(wroot, wdir))
                for uu in ds_base.iterdir():
                    if uu.name.endswith('.xlsx'):
                        meta_dic = chuli_meta(sig[2:], uu)
                    elif uu.name.endswith('.md'):
                        pp_data['cnt_md'] = open(str(uu.absolute())).read()
                    elif uu.name.startswith('thumbnail_'):
                        pp_data['logo'] = os.path.join(wroot, wdir,
                                                       uu.name).strip('.')

    kwargsa = {
        'def_cat_uid': catid,
        'cat_id': catid,
    }
    MPost.add_or_update(uid, pp_data)
    update_category(uid, pp_data, kwargsa)
    MPost2Catalog.add_record(uid, catid)
Ejemplo n.º 5
0
def do_tabapp():
    print('==============================')
    print('For Infor ... ')
    from torcms.model.post_model import MPost
    from torcms.model.infor2catalog_model import MInfor2Catalog
    mpost = MPost()
    mpost2tag = MInfor2Catalog()

    from model_ent.infor_model import MInfor
    minfor = MInfor()
    info_recs = minfor.query_all(20000)
    for info_rec in info_recs:
        # print(info_rec.uid)
        # info_tag = mpost2tag.get_entry_catalog(info_rec.uid).uid
        extinfo = info_rec.extinfo
        if 'def_cat_uid' in extinfo:
            old_cat_id = extinfo['def_cat_uid']
            extinfo['def_cat_uid'] = retag(old_cat_id)
            extinfo['def_cat_pid'] = retag(old_cat_id)[:2] + '00'
        # print(extinfo['def_cat_uid'])

        post_data = {
            'title': info_rec.title,
            'user_name': info_rec.user_name,
            'logo': info_rec.logo,
            'cnt_md': unescape(info_rec.cnt_md),
            'keywords': info_rec.keywords,
            'kind': '2',
            'extinfo': extinfo,
            # 'time_create': info_rec.time_create,
            'time_update': info_rec.time_update,
        }
        # mpost.insert_data('m' + info_rec.uid, post_data)
        # print(info_rec.uid)
        mpost.add_or_update(info_rec.uid, post_data)
        if 'def_cat_uid' in extinfo:
            try:
                mpost2tag.add_record(info_rec.uid, extinfo['def_cat_uid'], 1)
            except:
                print(info_rec.title)
Ejemplo n.º 6
0
class TestMPost():
    def setup(self):
        print('setup 方法执行于本类中每条用例之前')
        self.uu = MPost()
        self.m2c = MPost2Catalog()
        self.ml = MLabel()
        self.m2l = MPost2Label()
        self.labeluid = '9999'
        self.raw_count = self.uu.get_counts()
        self.post_title = 'ccc'
        self.uid = tools.get_uu4d()
        self.post_id = '66565'
        self.tag_id = '2342'
        self.post_id2 = '89898'
        self.slug = 'huio'

    def test_insert(self):
        raw_count = self.uu.get_counts()

        post_data = {
            'title': self.post_title,
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
            'view_count': 1,
            'logo': '/static/',
            'keywords': 'sdf',
        }
        self.uu.create_post(self.uid, post_data)
        new_count = self.uu.get_counts()

        tt = self.uu.get_by_uid(self.uid)
        assert tt.title == post_data['title']
        assert tt.cnt_md == tornado.escape.xhtml_unescape(post_data['cnt_md'])
        assert tt.cnt_html == tools.markdown2html(post_data['cnt_md'])
        assert raw_count + 1 == new_count
        self.tearDown()

    def test_insert_2(self):
        '''Wiki insert: Test invalid title'''

        post_data = {
            'title': '',
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
            'view_count': 1,
            'logo': '/static/',
            'keywords': 'sdf',
        }
        uu = self.uu.create_post(self.uid, post_data)
        assert uu == False

        post_data = {
            'title': '1',
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
            'view_count': 1,
            'logo': '/static/',
            'keywords': 'sdf',
        }
        uu = self.uu.create_post(self.uid, post_data)
        assert uu == False

        post_data = {
            'title': '天',
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
            'view_count': 1,
            'logo': '/static/',
            'keywords': 'sdf',
        }
        uu = self.uu.create_post(self.uid, post_data)
        self.tearDown()
        assert uu == False

    def add_message(self, **kwargs):
        post_data = {
            'name': kwargs.get('name', 'category'),
            'slug': kwargs.get('slug', self.slug),
            'order': kwargs.get('order', '0'),
            'kind': kwargs.get('kind1', '1'),
            'pid': kwargs.get('pid', '0000'),
        }
        MCategory.add_or_update(self.tag_id, post_data)

        p_d = {
            'title': kwargs.get('title', 'iiiii'),
            'cnt_md': kwargs.get('cnt_md', 'grgr'),
            'time_create': kwargs.get('time_create', '1992'),
            'time_update': kwargs.get('time_update', '1996070600'),
            'user_name': kwargs.get('user_name', 'yuanyuan'),
            'view_count': kwargs.get('view_count', 1),
            'logo': kwargs.get('logo', 'prprprprpr'),
            'memo': kwargs.get('memo', ''),
            'order': kwargs.get('order', '1'),
            'keywords': kwargs.get('keywords', ''),
            'extinfo': kwargs.get('extinfo', {}),
            'kind': kwargs.get('kind2', '1'),
            'valid': kwargs.get('valid', 1),
        }
        post_id = kwargs.get('post_id', self.post_id)
        MPost.get_by_uid(post_id)

        MPost.create_post(post_id, p_d)

        MPost2Catalog.add_record(self.post_id, self.tag_id)

    def test_get_by_title(self):

        post_data = {
            'title': self.post_title,
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
            'view_count': 1,
            'logo': '/static/',
            'keywords': 'sdf',
        }
        uid = self.uu.create_post(self.uid, post_data)

        ss = self.uu.get_by_uid(uid)
        assert ss.title == post_data['title']

        self.tearDown()

    def test_get_by_title2(self):
        '''Test Wiki title with SPACE'''

        post_data = {
            'title': '  ' + self.post_title + '  ',
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
            'view_count': 1,
            'logo': '/static/',
            'keywords': 'sdf',
        }
        uid = self.uu.create_post(self.uid, post_data)

        ss = self.uu.get_by_uid(uid)
        assert ss.title == self.post_title

        self.tearDown()

    def test_query_cat_random(self):
        self.add_message()
        p = {'limit': 300}
        TF = False
        qq = self.uu.query_cat_random(self.tag_id, **p)
        for i in qq:

            if i.uid == self.post_id:
                TF = True
        self.tearDown()
        assert TF

    def test_query_recent_most(self):
        self.add_message()
        qq = self.uu.query_recent_most(num=300)
        TF = False
        for i in qq:

            if i.uid == self.post_id:

                TF = True
        self.tearDown()
        assert TF

    def test_query_recent(self):
        self.add_message()
        qq = self.uu.query_recent(num=300)
        TF = False
        for i in qq:

            if i.uid == self.post_id:
                TF = True
        self.tearDown()
        assert TF

    def test_query_all(self):
        self.add_message()
        kwargs = {
            'limit': 300,
        }
        pp = self.uu.query_all(**kwargs)
        TF = False
        for i in pp:

            if i.uid == self.post_id:
                TF = True
        self.tearDown()
        assert TF

    def test_query_keywords_empty(self):
        self.add_message()
        pp = self.uu.query_keywords_empty()
        TF = False
        for i in pp:

            if i.uid == self.post_id:
                TF = True
        self.tearDown()
        assert TF

    def test_query_dated(self):
        self.add_message()
        qq = self.uu.query_dated(num=2000)

        TF = False
        for i in qq:

            if i.uid == self.post_id:
                TF = True
        self.tearDown()
        assert TF

    def test_query_most_pic(self):
        self.add_message()
        qq = self.uu.query_most_pic(300)
        TF = False
        for i in qq:

            if i.uid == self.post_id:
                TF = True
        self.tearDown()
        assert TF

    def test_query_cat_recent(self):
        self.add_message()
        qq = self.uu.query_cat_recent(self.tag_id, num=300)
        TF = False

        for i in qq:

            if i.uid == self.post_id:
                TF = True
        self.tearDown()
        assert TF

    def test_query_most(self):
        self.add_message()
        qq = self.uu.query_most(num=300)
        TF = False
        for i in qq:

            if i.uid == self.post_id:
                TF = True
        self.tearDown()
        assert TF

    def test_delete(self):
        self.add_message()
        qq = self.uu.delete(self.post_id)

        assert qq

        self.tearDown()

    def test_update_view_count_by_uid(self):

        post_data = {
            'title': self.post_title,
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
            'view_count': 1,
            'logo': '/static/',
            'keywords': 'sdf',
        }
        self.uu.create_post(self.uid, post_data)

        rec = self.uu.get_by_uid(self.uid)

        viewcount0 = rec.view_count
        assert viewcount0 >= 1
        for x in range(100):
            self.uu.update_misc(rec.uid, count=True)

        viewcount1 = self.uu.get_by_uid(self.uid).view_count

        self.tearDown()
        assert viewcount1 >= 101

    def test_upate(self):
        y = {'logo': '123123'}
        self.add_message(**y)
        qq = {
            'title': 'oppssss',
            'logo': 'fffff',
            'cnt_md': 'iiii',
            'user_name': 'yy'
        }
        self.uu.update(self.post_id, qq)
        aa = self.uu.get_by_uid(self.post_id)
        assert aa.logo == qq['logo']
        assert aa.title == qq['title']

        self.tearDown()

    def test_get_by_uid(self):
        y = {'logo': '123123'}
        self.add_message(**y)
        a = self.uu.get_by_uid(self.post_id)
        assert a.logo == y['logo']
        self.tearDown()

    def test_get_counts(self):
        a = self.uu.get_counts()
        self.add_message()
        b = self.uu.get_counts()
        assert a + 1 >= b

        self.tearDown()

    def test_update_field(self):
        y = {'logo': '123123'}
        self.add_message(**y)
        self.uu.update_field(self.post_id, self.post_id2)
        bb = self.uu.get_by_uid(self.post_id)
        aa = self.uu.get_by_uid(self.post_id2)

        assert bb == None
        assert aa.logo == y['logo']

        self.tearDown()

    def test_update_cnt(self):
        self.add_message()
        qq = {'cnt_md': 'iiii', 'user_name': ' yy  '}
        self.uu.update_cnt(self.post_id, qq)
        bb = self.uu.get_by_uid(self.post_id)
        assert bb.cnt_md == qq['cnt_md']

        self.tearDown()

    def test_update_order(self):
        self.add_message()

        self.uu.update_order(self.post_id, '1')
        bb = self.uu.get_by_uid(self.post_id)
        assert bb.order == '1'

        self.tearDown()

    def test_add_or_update(self):
        bb = self.uu.get_by_uid(self.post_id)

        assert bb == None
        p_d = {
            'title': 'iiiii',
            'cnt_md': 'grgr',
            'time_create': '1992',
            'time_update': '1996070600',
            'user_name': 'yuanyuan',
            'view_count': '1',
            'logo': 'prprprprpr',
            'memo': '',
            'order': '1',
            'keywords': '',
            'extinfo': {},
            'kind': '1',
            'valid': '1',
        }
        self.uu.add_or_update(self.post_id, p_d)
        bb = self.uu.get_by_uid(self.post_id)
        assert bb.title == p_d['title']
        qq = {
            'title': 'oppssss',
            'logo': 'fffff',
            'cnt_md': 'iiii',
            'user_name': 'yy'
        }
        self.uu.add_or_update(self.post_id, qq)
        aa = self.uu.get_by_uid(self.post_id)
        self.tearDown()
        assert aa.logo == qq['logo']
        assert aa.title == qq['title']
        self.tearDown()

    def test_query_random(self):
        self.add_message()
        q = {'num': 300}
        qq = self.uu.query_random(**q)

        TF = False
        for i in qq:

            if i.uid == self.post_id:
                TF = True
        self.tearDown()
        assert TF

    def test_query_recent_edited(self):
        self.add_message()
        qq = self.uu.query_recent_edited(1555)

        TF = False
        for i in qq:

            if i.uid == self.post_id:
                TF = True
        self.tearDown()
        assert TF

    def test_query_by_tag(self):
        TF = False
        self.add_message()
        qq = self.uu.query_by_tag(self.tag_id)
        print(qq.count())

        for i in qq:
            print(i.title)
            if i.uid == self.post_id:
                TF = True
        self.tearDown()
        assert TF

    def test_query_cat_recent_with_label(self):
        name = 'kkkk'
        p_d = {'extinfo': {'def_tag_arr': name}}
        self.add_message(**p_d)

        self.uu.query_cat_recent_with_label(self.tag_id, label=name, num=300)
        qq = self.uu.get_by_uid(self.post_id)
        assert qq.extinfo == p_d['extinfo']
        self.tearDown()

    def test_query_cat_recent_no_label(self):
        self.add_message()

        qq = self.uu.query_cat_recent_no_label(self.tag_id, num=300)
        print(qq.count())
        print(qq)

        assert qq[0].uid == self.post_id
        self.tearDown()

    def test_query_total_cat_recent(self):
        name = 'kkkk'
        p_d = {'extinfo': {'def_tag_arr': name}}
        self.add_message(**p_d)
        qq = self.uu.query_total_cat_recent([self.tag_id, '9090'],
                                            label=name,
                                            num=300)
        assert qq[0].uid == self.post_id
        self.tearDown()

    def test_query_total_cat_recent_no_label(self):
        self.add_message()
        qq = self.uu.query_total_cat_recent_no_label([self.tag_id], num=300)

        assert qq[0].uid == self.post_id
        self.tearDown()

    def test_get_next_record(self):
        self.add_message()

        q = {
            'post_id': self.post_id2,
            'title': '90909090',
            'cnt_md': 'oosdfsfofsf',
            'time_create': '1996'
        }
        self.add_message(**q)
        qq = self.uu.get_next_record(self.post_id2)
        print(qq)
        assert qq.uid == self.post_id
        self.tearDown()

    def test_get_previous_record(self):
        self.add_message()
        q = {
            'post_id': self.post_id2,
            'title': '90909090',
            'cnt_md': 'oosdfsfofsf',
            'time_create': '1996'
        }
        self.add_message(**q)
        qq = self.uu.get_previous_record(self.post_id)
        assert qq.uid == self.post_id2
        self.tearDown()

    def test_get_all(self):
        ose = self.uu.get_all(kind='1')
        TF = True
        for i in ose:
            if self.post_id == i.uid:
                TF = False
        assert TF

        self.add_message()
        eee = self.uu.get_all(kind='1')
        TF = False
        for i in eee:
            if self.post_id == i.uid:
                TF = True
        self.tearDown()
        assert TF

    def test_update_jsonb(self):
        p = {'ii': 'ii00ii'}
        self.add_message()
        self.uu.update_jsonb(self.post_id, p)
        aa = self.uu.get_by_uid(self.post_id)

        assert aa.extinfo == p

        self.tearDown()

    def test_modify_meta(self):
        self.add_message()
        p_d = {
            'title': 'qqqii',
            'cnt_md': 'qwqwqw',
            'time_create': '1999',
            'time_update': '2019',
            'user_name': 'max',
            'view_count': '1',
            'logo': 'opps',
            'memo': '',
            'order': '1',
            'extinfo': {},
            'kind': '1',
            'valid': '1',
        }
        self.uu.modify_meta(self.post_id, p_d)
        aa = self.uu.get_by_uid(self.post_id)
        self.tearDown()
        assert aa.title == p_d['title']

    def test_modify_init(self):
        self.add_message()
        p_d = {'keywords': 'io'}
        self.uu.modify_init(self.post_id, p_d)
        aa = self.uu.get_by_uid(self.post_id)
        assert aa.keywords == p_d['keywords']

        self.tearDown()

    def test_get_view_count(self):

        p_d = {'view_count': 3}
        self.add_message(**p_d)
        qq = self.uu.get_view_count(self.post_id)

        assert qq == p_d['view_count']
        self.tearDown()

    def test_query_most_by_cat(self):
        self.add_message()
        a = self.uu.query_most_by_cat(catid=self.tag_id, kind='1')
        assert a[0].uid == self.post_id
        self.tearDown()

    def test_query_least_by_cat(self):
        self.add_message()
        a = self.uu.query_least_by_cat(cat_str=self.tag_id, kind='1')
        assert a[0].uid == self.post_id
        self.tearDown()

    def test_get_by_keyword(self):
        p_d = {'title': 'yyyyy'}
        self.add_message(**p_d)
        aa = self.uu.get_by_keyword(p_d['title'], kind='1')
        assert aa[0].uid == self.post_id
        self.tearDown()

    def test_query_extinfo_by_cat(self):
        oo = 'd99s9s'
        p_d = {'extinfo': {'def_cat_uid': oo}}
        self.add_message(**p_d)
        aa = self.uu.query_extinfo_by_cat(oo, kind='1')
        assert aa[0].uid == self.post_id
        self.tearDown()

    def test_query_by_tagname(self):
        oo = 'd99s9s'
        p_d = {'extinfo': {'def_tag_arr': oo}}
        self.add_message(**p_d)
        aa = self.uu.query_by_tagname(oo, kind='1')
        assert aa[0].uid == self.post_id
        self.tearDown()

    def test_query_pager_by_tag(self):
        oo = 'd99s9s'
        p_d = {'extinfo': {'def_tag_arr': oo}}
        self.add_message(**p_d)
        aa = self.uu.query_pager_by_tag(oo, kind='1')
        assert aa[0].uid == self.post_id
        self.tearDown()

    def test_add_meta(self):
        p_d = {
            'title': 'qqqii',
            'cnt_md': 'qwqwqw',
            'time_create': '1999',
            'time_update': '2019',
            'user_name': 'max',
            'view_count': '1',
            'logo': 'opps',
            'memo': '',
            'order': '1',
            'kind': '1',
            'valid': 1,
        }
        self.uu.add_meta(self.post_id, p_d)

        aa = self.uu.get_by_uid(self.post_id)
        self.tearDown()
        assert aa.title == p_d['title']

    def test_query_under_condition(self):
        oo = {'def_tag_arr': 'd99s9s'}
        p_d = {'extinfo': oo}
        self.add_message(**p_d)
        aa = self.uu.query_under_condition(oo, kind='1')
        print(aa.count())
        assert aa[0].uid == self.post_id
        self.tearDown()

    def test_addata_init(self):
        p_d = {
            'sig': self.post_id,
            'title': 'qqq4ii',
            'cnt_md': 'qwqwqw',
            'user_name': 'max',
            'view_count': '1',
            'logo': 'opps',
            'memo': '',
            'order': '1',
            'cnt_html': 'dddd',
            'kind': '2',
            'valid': 1,
        }
        print('fddfsfdsfdsfd')
        self.uu.addata_init(p_d)
        print('fddfsfdsfdsfd')

        aa = self.uu.get_by_uid(self.post_id)
        print(aa)
        assert aa.title == p_d['title']

        self.tearDown()

    def test_query_list_pager(self):
        oo = {'def_tag_arr': 'd99s9s'}
        p_d = {'extinfo': oo}
        self.add_message(**p_d)
        qq = self.uu.query_list_pager(oo, 1, kind='1')
        print(qq[0])
        assert qq[0].uid == self.post_id

        self.tearDown()

    def test_count_of_certain_kind(self):
        a = self.uu.count_of_certain_kind(1)
        self.add_message()
        b = self.uu.count_of_certain_kind(1)
        assert a + 1 <= b

        self.tearDown()

    def test_total_number(self):
        a = self.uu.total_number(1)
        self.add_message()
        b = self.uu.total_number(1)
        assert a + 1 <= b

        self.tearDown()

    def tearDown(self):
        print("function teardown")
        tt = self.uu.get_by_uid(self.uid)

        if tt:
            print('翻翻翻翻翻翻翻翻翻翻翻翻翻翻翻翻翻翻3')
            self.uu.delete(self.uid)
        tt = MCategory.get_by_uid(self.tag_id)
        if tt:
            MCategory.delete(self.tag_id)
        tt = self.uu.get_by_uid(self.post_id)
        if tt:
            MCategory.delete(self.tag_id)

            MPost.delete(self.post_id2)
            MPost.delete(self.post_id)

            MPost2Catalog.remove_relation(self.post_id, self.tag_id)
            print('545456365635653')

        tt = MLabel.get_by_slug(self.slug)
        if tt:
            print('8888888888')
            MLabel.delete(tt.uid)
Ejemplo n.º 7
0
def get_meta(catid, sig, kind_sig=''):
    if kind_sig:
        pass
    else:
        return
    meta_base = './static/xx_mds'
    if os.path.exists(meta_base):
        pass
    else:
        return False

    for wroot, wdirs, wfiles in os.walk(meta_base):
        for wdir in wdirs:

            if wdir.lower().endswith(sig[1:]):
                ds_base = pathlib.Path(os.path.join(wroot, wdir))
                pp_data = {'logo': '', 'kind': kind_sig}

                for uu in ds_base.iterdir():
                    if uu.name.endswith('.md'):
                        meta_dic = chuli_meta(sig, uu)

                        if 'title' in meta_dic:
                            pass
                        else:
                            continue

                        pp_data['title'] = meta_dic['title']
                        pp_data['cnt_md'] = meta_dic['cnt_md']
                        pp_data['user_name'] = meta_dic['author']
                        pp_data['gcat0'] = catid
                        pp_data['def_cat_pid'] = catid[:2] + '00'
                        pp_data['valid'] = 1
                        # 将主要数据添加到外扩展
                        pp_data['extinfo'] = {}

                        kwargsa = {
                            'gcat0': catid,
                            'cat_id': catid,
                        }
                    elif uu.name.startswith('thumbnail_'):
                        hou = os.path.splitext(uu.name)[-1]
                        if hou in [
                                '.jpg', '.png', '.JPG', '.PNG', 'jpeg', 'JPEG'
                        ]:
                            thum_path = gen_thumb(
                                os.path.join(wroot, wdir, uu.name),
                                'd' + sig[1:])
                            pp_data['logo'] = thum_path.strip('.')

                # ToDo: 未处理完

                dataset_id = 'dn' + sig[1:]
                the_entity = fix_entity_path(dataset_id)

                post_id = sig

                postinfo = MPost.get_by_uid(post_id)

                if postinfo:
                    postinfo.extinfo.update(pp_data['extinfo'])
                    pp_data['extinfo'] = postinfo.extinfo

                # pp_data['extinfo']['tag_data_classification'] = str(dwmode)

                if the_entity:
                    pp_data['extinfo']['tag__file_download'] = the_entity
                    MPost.update_jsonb(post_id, pp_data['extinfo'])
                else:
                    # 如果未找到实体
                    pass
                    # update_category(post_id, pp_data)

                    # ws.cell(row=i, column=2).value = pp_data['title']
                # Write a copy with titles.

                MPost.add_or_update(sig, pp_data)

                update_category(sig, pp_data, kwargsa)

                update_label(sig, pp_data)

                MPost2Catalog.add_record(sig, catid)

                return pp_data['title']
Ejemplo n.º 8
0
def import_tables():
    inws = pathlib.Path('./database/datacn_tables')
    print(inws)
    # for y in os.listdir(inws):
    #     print(y)
    for cat_path in inws.iterdir():
        if cat_path.is_dir():
            uu_arr = cat_path.name.split('_')
            uid = uu_arr[0]
            print(uid)

            for xlsx in cat_path.iterdir():
                if xlsx.suffix.lower() == '.xlsx' and '数据指标列表' not in xlsx.name:
                    print(xlsx.name)
                    the_name = xlsx.name[:-5]
                    name_arr = the_name.split('_')
                    # ToDo: 下面强制断掉,有问题
                    post_uid = ('t' + name_arr[0]).lower()[:5]
                    if len(name_arr) > 1:
                        post_title = '_'.join(name_arr[1:])
                    else:
                        post_title = name_arr[0]

                    print(post_uid)
                    pp_data = {
                        'title': post_title,
                        'cnt_md': 'aa',
                        'user_name': 'admin',
                        'logo': 'log',
                        'def_cat_uid': uid,
                        'def_cat_pid': '5000',
                        'kind': '5',

                        'extinfo': {
                            'def_tab_path': '/'.join(str(xlsx)[:-5].split('/')[-2:]),
                        }

                    }

                    # title = title,

                    # cnt_md = tornado.escape.xhtml_escape(post_data['cnt_md'].strip()),
                    # cnt_html = tools.markdown2html(post_data['cnt_md']),
                    # uid = post_uid,
                    # time_create = post_data.get('time_create', tools.timestamp()),
                    # time_update = post_data.get('time_update', tools.timestamp()),
                    # user_name = post_data['user_name'],
                    # view_count = post_data['view_count'] if 'view_count' in post_data else 1,
                    # logo = post_data['logo'],
                    # memo = post_data['memo'] if 'memo' in post_data else '',
                    # order = post_data['order'] if 'order' in post_data else '',
                    # keywords = post_data['keywords'] if 'keywords' in post_data else '',
                    # extinfo = post_data['extinfo'] if 'extinfo' in post_data else {},
                    # kind = post_data['kind'] if 'kind' in post_data else '1',
                    # valid = post_data.get('valid', 1)
                    #
                    print('x' * 50)
                    print(post_uid)
                    print(pp_data)
                    MPost.add_or_update(post_uid, pp_data)
                    # print(xlsx.absolute())
                    # MPost.update_misc(post_uid, def_tab_path = xlsx.absolute())
                    kwargsa = {
                        'def_cat_uid': uid,
                        'cat_id': uid,
                    }
                    update_category(post_uid, pp_data, kwargsa)
                    MPost2Catalog.add_record(post_uid, uid)