Hi, I propose a rednotebook 2 journee converter. It has to be improved.
from os import listdir
from os.path import isfile, join
import re
sourcedir = '../01_datainput/'
destdir = '../02_dataoutput/'
sourcefiles = [f for f in listdir(sourcedir) if isfile(join(sourcedir, f))]
for sourcefile in sourcefiles:
f = open((sourcedir + sourcefile), "r")
daynote=""
isfirstmounthday = True
for line in f:
newdaysearch = re.search("^.[0-9]:$", line)
if newdaysearch: # is it the line that contains the new day?
if not isfirstmounthday: # if it is not the first day of the file, I have to save the gathered information
if isopensinglequotepresent:
daynote = daynote[::-1]
daynote = daynote.replace("'", "", 1)
daynote = daynote[::-1]
daynote=daynote.replace('\\n', '\n').replace('\\t', '\t')
fwrite=open((destdir + filedestname), "w")
fwrite.write(daynote)
fwrite.close()
daynote=""
#let's compute the new filename
newdaystring=line.replace(":","")
newdaystring=newdaystring.replace(" ","")
newdaystring = newdaystring.replace('\n' '', "")
filedestname=sourcefile.replace(".txt","")
filedestname=filedestname+'-'+newdaystring+".txt"
isfirstmounthday = False
else:
if daynote == "":
isopensinglequotepresent = False
line=line.replace(" text: ","")
if line[0] == "'":
line = line.replace("'", "",1)
isopensinglequotepresent=True
#if not re.search(". *'$",line):
daynote=daynote + line
# saving the last day in the file
if isopensinglequotepresent:
daynote = daynote[::-1]
daynote = daynote.replace("'", "", 1)
daynote = daynote[::-1]
daynote = daynote.replace('\\n', '\n').replace('\\t', '\t')
fwrite = open((destdir + filedestname), "w")
fwrite.write(daynote)
fwrite.close()
f.close()