Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rednotebook 2 journee skeleton #4

Closed
marcorighi opened this issue Oct 19, 2023 · 3 comments
Closed

rednotebook 2 journee skeleton #4

marcorighi opened this issue Oct 19, 2023 · 3 comments

Comments

@marcorighi
Copy link

marcorighi commented Oct 19, 2023

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()



@adueck
Copy link
Owner

adueck commented Oct 29, 2023

Wow, thanks for this. I actually used rednotebook before I built this, and this is a really useful conversion script. I might use this manually or archive this somewhere. If this could be ported to js/ts perhaps I could add a feature where people could import their rednotebook ?

@marcorighi
Copy link
Author

The code is free and freeware.

@adueck
Copy link
Owner

adueck commented Oct 30, 2023

Great, thanks for sharing! I'll close this for now but will keep this as a reference and would be happy to use it in the future.

@adueck adueck closed this as completed Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants