Beispiel #1
0
def absAPPhtml(path,
               outdir='',
               regrex1=re.compile('检例第(\d*)号'),
               rc=re.compile('(.*?案\s*(检例第\d*号))'),
               p1=re.compile('【要旨】'),
               p2=re.compile('\【\w*】'),
               yz=True):
    if outdir == '':
        outdir = 'itempdit'
    absSPP(path=path, tdir=outdir, rc=rc, p1=p1, p2=p2, yz=yz)
    ss = GFlist(outdir, regrex1=regrex1)
    Tfile = [i[1] for i in ss]
    htmlcode = _hh(outdir)
    tb, ctt = make_Mulu_content(Tfile)
    htmlName = 'outputabsSPP.html'
    try:
        html = open(htmlName, 'w', encoding='utf8')
        html.write(htmlcode)
        html.write(tb)
        html.write(ctt)
    except:
        html = open(htmlName, 'w', encoding='gbk')
        html.write(htmlcode)
        html.write(tb)
        html.write(ctt)

    html.write('</body></html>')
    html.close()
    shutil.rmtree(outdir)
    return

    return
Beispiel #2
0
def C2htmlBase(txtpath,output='outputbase.html',m1=re.compile(r'^第\w{1,3}[编|篇]'),m2=re.compile(r'^第\w{1,3}章'),m3=re.compile(r'^第\w{1,3}节'),m4=re.compile(r'^\w{1,3}、'),index=True,py=False):
    """
    txtpath:为单独的文件或一段字符
    
    """
    p=getcsspath()
    ft='''\n<link rel="stylesheet" type="text/css" href="%s" />'''
    ll=title+'\n'+title1+ft%p+title2+'\n'
    #print(ll)
    
    files=[]
    if os.path.isfile(txtpath):
        if os.path.splitext(txtpath)[1].lower() in ['.txt','.doc','.docx']:
            files.append(txtpath)
            #tname=os.path.splitext(os.path.basename(txtpath))[0]
                
    elif isinstance(txtpath,str):
        path123='tempsdfsf.txt'
        fff=open(path123,'w',encoding='utf8')
        fff.write(txtpath)
        fff.close()
        files.append(path123)
                
    else:
        print('Please input a file for txt,doc,or strings')
        sys.exit()
        

    tb,ctt=make_Mulu_content(files,m1=m1,m2=m2,m3=m3,index=index,py=py)
    if os.path.exists(output):
       os.remove(output)

    try:
        if os.path.exists(path123):
            os.remove(path123)
    except:
        pass
    
    try:        
        html=open(output,'a',encoding='utf8')
        html.write(ll)
        #html.write('<div id="content">\n')
        html.write('<div id="content",style="background-color:#C7EDF0">\n')
        html.write(tb)
        html.write(ctt)
    except:
        html=open(output,'a',encoding='gbk')
        html.write(ll)
        #html.write('<div id="content">\n')
        html.write('<div id="content",style="background-color:#C7EDF0">\n')
        html.write(tb)
        html.write(ctt)
    html.write(endd)
    html.close()
    print("\n转换成功,保存在%s"%output)
    return
Beispiel #3
0
def txt2htmlv1(txtName,
               output="outputtxt",
               m1=re.compile(r'^第\w{1,3}[编|篇]'),
               m2=re.compile(r'^第\w{1,3}章'),
               m3=re.compile(r'^第\w{1,3}节'),
               index=True,
               py=False):
    """
    txtName:文件的名称(含所在的文件夹)
    index:  True,将第四节的列入目录
             False,不含第四节的目录
    ---------------
    在python运行目录下生产一份html文件。
    """
    files = []
    htmlcode1 = _hh(txtName)

    if isinstance(txtName, str):
        files.append(txtName)
    elif isinstance(txtName, list):
        files.extend(txtName)

    if output == '':
        htmlName = "outputtxt.html"
    else:
        output = output + '.html'

    htmlName = output

    tb, ctt = make_Mulu_content(files, m1=m1, m2=m2, m3=m3, index=index, py=py)
    if os.path.exists(htmlName):
        os.remove(htmlName)
    try:
        html = open(htmlName, 'a', encoding='utf8')
        html.write(htmlcode1)
        html.write(tb)
        html.write(ctt)
    except:
        html = open(htmlName, 'a', encoding='gbk')
        html.write(htmlcode1)
        html.write(tb)
        html.write(ctt)

    html.write('</body></html>')
    html.close()
    print("\n转换成功,保存在%s" % htmlName)
    return
Beispiel #4
0
def txt2html_inonefile(txtName,
                       m1=re.compile(r'^第\w{1,3}[编|篇]'),
                       m2=re.compile(r'^第\w{1,3}章'),
                       m3=re.compile(r'^第\w{1,3}节'),
                       index=True,
                       py=False):
    """
    txtName:文件的名称(含所在的文件夹)
    index:  True,将第四节的列入目录
             False,不含第四节的目录
    ---------------
    在txtName文件目录下生产一html文件。
    """
    files = []
    htmlcode1 = _hh(txtName)
    if os.path.isfile(txtName):
        path = os.path.abspath(txtName)
        files.append(path)
        htmlName = os.path.splitext(path)[0] + '.html'
    else:
        print("%s is not file...." % txtName)
        sys.exit()

    tb, ctt = make_Mulu_content(files, m1=m1, m2=m2, m3=m3, index=index, py=py)
    if os.path.exists(htmlName):
        os.remove(htmlName)
    try:
        html = open(htmlName, 'w', encoding='utf8')
        html.write(htmlcode1)
        html.write(tb)
        html.write(ctt)
    except:
        html = open(htmlName, 'w', encoding='gbk')
        html.write(htmlcode1)
        html.write(tb)
        html.write(ctt)

    html.write('</body></html>')
    html.close()
    print("\n转换成功,保存在%s" % htmlName)
    return
Beispiel #5
0
def C2html(txtpath,output='output',m1=re.compile(r'^第\w{1,3}[编|篇]'),m2=re.compile(r'^第\w{1,3}章'),m3=re.compile(r'^第\w{1,3}节'),m4=re.compile(r'^\w{1,3}、'),index=True,py=False):
    """
    txtpath:为单独的文件、一系列文件或一段字符
    并将这些文件中的内容输出到一份html 文件中
    """
    p=getcsspath()
    ft='''\n<link rel="stylesheet" type="text/css" href="%s" />'''
    ll=title+'\n'+title1+ft%p+title2+'\n'
    #print(ll)
    
    files=[]

    if isinstance(txtpath,list):
        for f in txtpath:
            if os.path.isfile(f) and (os.path.splitext(f)[1].lower() in ['.txt','.doc','.docx']):
                files.append(f)    
    elif os.path.isfile(txtpath):
        if os.path.splitext(txtpath)[1].lower() in ['.txt','.doc','.docx']:
            files.append(txtpath)

                
    elif isinstance(txtpath,str):
        path123='tempsdfsf.txt'
        fff=open(path123,'w',encoding='utf8')
        fff.write(txtpath)
        fff.close()
        files.append(path123)
                
    else:
        sys.exit()

    if output=='':
        output='output.html'
    else:
        output=output+'.html'

    if os.path.exists(output):
       os.remove(output)

    
    tb,ctt=make_Mulu_content(files,m1=m1,m2=m2,m3=m3,index=index,py=py)
    try:
        html=open(output,'a',encoding='utf8')
        html.write(ll)
        #html.write('<div id="content">\n')
        html.write('<div id="content",style="background-color:#C7EDF0">\n')
        html.write(tb)
        html.write(ctt)
    except:
        html=open(output,'a',encoding='gbk')
        html.write(ll)
        #html.write('<div id="content">\n')
        html.write('<div id="content",style="background-color:#C7EDF0">\n')
        html.write(tb)
        html.write(ctt)

        

    html.write(endd)
    html.close()
    print("\n转换成功,保存在%s"%output)
    try:
        if os.path.exists(path123):
            os.remove(path123)
    except:
        pass
    return
Beispiel #6
0
def absTFilehtml(txtpath,
                 func=abssplit,
                 rc=re.compile('裁判要点\W*(.*?\s*.*?)\W*相关法条'),
                 p1=re.compile('裁判要点'),
                 p2=re.compile('相关法条'),
                 regrex1=None,
                 Research=None,
                 index=True,
                 Startw=None,
                 m1=re.compile(r'^第\w{1,3}[编|篇]'),
                 m2=re.compile(r'^第\w{1,3}章'),
                 m3=re.compile(r'^第\w{1,3}节')):
    """
    rc:需要提取的主要内容
    regrex1:
    """

    files = []
    if isinstance(txtpath, list):
        files.extend(txtpath)
    elif txtpath is None:
        txtpath = os.getcwd()
        ss = GFlist(txtpath, regrex1=regrex1, research=Research, startw=Startw)
        files = [i[1] for i in ss]
    elif os.path.isdir(txtpath):
        ss = GFlist(txtpath, regrex1=regrex1, research=Research, startw=Startw)
        files = [i[1] for i in ss]
    tdir = 'temp_dir'
    if not os.path.exists(tdir):
        os.mkdir(tdir)

    htmlcode = _hh(txtpath)
    Tfile = []
    if func.__name__ == 'abstract':
        for f in files:
            bn = os.path.basename(f)
            nf = os.path.join(tdir, bn)
            text = func(f, rc=rc)
            try:
                with open(nf, 'w', encoding='utf8') as gf:
                    gf.write(text)
                Tfile.append(nf)
            except:
                pass
    elif func.__name__ == 'abssplit':
        for f in files:
            bn = os.path.basename(f)
            nf = os.path.join(tdir, bn)
            text = func(f, p1=p1, p2=p2)
            #print(text)
            try:
                with open(nf, 'w', encoding='utf8') as gf:
                    gf.write(text)
                Tfile.append(nf)
            except:
                pass

    tb, ctt = make_Mulu_content(Tfile, m1=m1, m2=m2, m3=m3, index=index)
    htmlName = 'outputabs.html'
    try:
        html = open(htmlName, 'w', encoding='utf8')
        html.write(htmlcode)
        html.write(tb)
        html.write(ctt)
    except:
        html = open(htmlName, 'w', encoding='gbk')
        html.write(htmlcode)
        html.write(tb)
        html.write(ctt)

    html.write('</body></html>')
    html.close()
    shutil.rmtree(tdir)

    return