recommendations for personal journaling application

Ant antroy at gmail.com
Sun Oct 8 15:53:23 EDT 2006


Donnie Rhodes wrote:
...
>
> Thank you all and I hope I'm not biting off too much at once...

Not if you break it up into pieces. Look at the things you want to do,
and in the first instance, create a function for each. Then you can
start to fill in the blanks, and if neccessary ask back here for advice
on each bit.

For example, your skeleton script may look something like:

def main():
    options = get_options()
    text = fetch_body()
    entry_data = parse_text(text, options)
    store_entry(entry_data)

def get_options():
    pass

def fetch_body()
    pass
...

if __name__ == "__main__":
    main()

Ideas for the various parts:

get_options() - getopt or optparse modules (the former is simpler to
start with);

fetch_body() - just read from sys.stdin (that way you can also pipe
text into it from a file or the output from another program as well);

parse_text() - regexes could suffice if the flags and what they are
supposed to do is simple, otherwise a grammar parsing module could be
useful such as pyparsing (http://pyparsing.wikispaces.com/);

store_entry() - I'd probably go with XML for the storage format if you
really want to store the entries in a single text file, as you can
structure it well, there are good tools in python 2.5 for building xml
(xml.etree.ElementTree) and you could implement a fast search engine
using SAX. Otherwise a database may be a better option (e.g. sqlite).




More information about the Python-list mailing list