remove_linebreaks.py 943 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
from pathlib import Path
import re

pathlist = Path("/home/colm/git/OSP/osp.tools.osp-blog/content").glob('**/*.md')
for path in pathlist:
    path_in_str = str(path)
    data = open(path_in_str, 'r+')
    c = data.read()
    t0 = re.findall(r'({[^}]*})', c)
    if len(t0) == 0 :
        continue
    else:
        t0 = t0[0]
        t1 = t0.replace('\n', ' ')
        t1 = t1[:1] + ': ' + t1[1:]
        print(t1)
        t2 = re.sub(r'({[^}]*})', t1, c)
        print(t2)
        f = open(path, 'w')
        f.write(t2)
        f.close()










    # if len(t0) == 0 :
    #     continue
    # else :
    #     t0 = ''.join(t0)
    #     t0 = t0.split(':')
    #     t1 = t0[1].split( )
    #     t1 = t1[0]
    #     newtags = t0[0] + ': ' + t1 + ',' + t0[2]
    # t2 = re.findall(r'Tags: [a-zA-Z]*\nTags:.*\n', c)
    # t3 = re.sub(r'Tags: [a-zA-Z]*\nTags:.*\n', newtags, c)
    # f = open(path, 'w')
    # f.write(t3)
    # f.close()