Пример #1
0
def readSimpleNote(fname):
    n = Note()
    f = open(fname, "r")
    tmp = f.read()
    f.close()

    tmp = tmp.splitlines()
    n.setTitle(tmp[0])

    # collect body
    msg = ""
    for i in range(1, len(tmp)):
        msg += tmp[i] + "\n"

    n.setBody(msg)

    return 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
Пример #3
0
        msg = msg.rstrip()  # remove all trailing newlines

        msg += "\n"
        msg += "\n"

        f = open(self.tmpNoteFile, "w")
        f.write(msg)
        f.close()


# --------------------------------------------------
# Testing
if __name__ == "__main__":
    note1 = Note()
    note1.setTitle("note number 1")
    note1.setBody("Blaablaa, this is comment.")

    note2 = Note()
    note2.setTitle("note number 2")
    note2.setBody("blaablaa, this is another comment.")

    note3 = Note()
    note3.setTitle("Lenghty note")
    note3.setBody("This is a note with a very long text body.\n" +
                  "it continues all the way to here. and to \n" +
                  "here: Seems long, right?. Now it finally almost.\n" +
                  "here: Seems long, right?. xxx xxx xxx xxx xxx x.\n" +
                  "here: Seems long, right?. Now it finally ends.")

    note4 = Note()
    note4.setTitle("Different note")