Esempio n. 1
0
def createTODO(directory):

    # get files
    allFiles = [f for f in listdir(directory) if isfile(join(directory, f))]
    todoFiles = [f for f in allFiles if f[0] != "."]
    # print(todoFiles)

    # create notebook
    nb = NoteBook()
    nb.setTitle("TODO")

    # nb.inbox.print(msg)
    # nb.tasklist.print(msg)

    for todof in todoFiles:
        n = readNoteFile(directory + "/" + todof)
        #print("adding note {}".format(todof))
        nb.addNote(n)

    # finally, create task list based on todo projects
    nb.tasklist.createTasks(nb.notes)

    return nb
Esempio n. 2
0
def readTodoFile(fname):

    nbtmp = NoteBook()
    nbtmp.setTitle("Updated TODO")
    nbtmp.tmpNoteFile = "notebook-tmp-C.md"

    f = open(fname, "r")
    tmp = f.read()
    f.close()

    # print("tmp file content--------------")
    tmp = tmp.splitlines()
    # print(tmp)

    # add trailing newlines for easier parsing
    # for i in range(len(tmp)):
    #    tmp[i] += "\n"

    # filter header out
    c = 0
    while True:
        if c >= len(tmp):
            break

        line = tmp[c]
        # print("skipping {}".format(line))

        mtitle = regexes.REtitle.match(line)
        if mtitle:
            break
        c += 1
    # print("skipping {}".format(c))

    ns = []
    hashes = []
    bodys = []

    body = ""
    while c < len(tmp):
        line = tmp[c]
        # print("{}".format( line ))

        mtitle = regexes.REtitle.match(line)
        mhash = regexes.REhash.match(line)
        mdate = regexes.REdate.match(line)
        mmdate = regexes.REmdate.match(line)
        mdiv = regexes.REdiv.match(line)

        if mtitle:
            n = Note()
            bodys.append(body)
            body = ""

            s = mtitle.group(1)
            s = s.replace("'",
                          "")  # strip ' from title (causes problems with rm)
            n.setTitle(s)
            ns.append(n)
            # ni += 1
        elif mdiv:
            # do nothing
            True
        elif mhash:
            s = mhash.group(1)
            hashes.append(s)
        elif mdate:
            n.setDate(mdate.group(1))
        elif mmdate:
            n.setDate(mmdate.group(1))
        else:
            body += line + "\n"
        c += 1
    bodys.append(body)  # append last hanging body

    # print("###########################################")
    for i, n in enumerate(ns):

        body = bodys[i + 1]
        # print("last char: vvv{}vvv".format(body[-2:]))

        # if (body[-2:] == "\n"):
        #    print("newline detected")
        #    body = body[:-2]

        # body = body[:-2] #strip trailing newline
        # body = body.rstrip()
        # body += "\n"
        # body += "\n"

        n.setBody(body)
        # print("{} -- {}".format(i, n.title))
        # print("{} hash is {}".format(i, n.hash() ))
        # print("----")
        # print("{}".format(n.body))
        # print("----")
        # print("{}".format(body))

        nbtmp.addNote(n)

    return nbtmp