Saturday, June 9, 2007

OlinDocs datbase generation (part the last)

All right so we left off with databases in all of the directories. Now it's time to put everything together and get it all in its final form. If you haven't been reading, this is not the place to start; try this instead.

This is all actually fairly easy and short. To combine all of the databases in all of the directories I use this little function.

def combine(path):
_mydb= open('/.../OlinDocs/docdb.txt','w')

_for location in path:
__tmp=open(location+'/part_db.txt','r')
__mydb.write(tmp.read())
__tmp.close()

_mydb.close()



Since path is a list of all of my locations already this just checks the directories where I just made some partial databases, reads the whole thing and puts it into the main database. Just iterate and enjoy the fun. The rest is actually just manipulating text to put it in the form I described in part two for the javascript so I won't really go into it. One little trick I will mention, is using str() on a list to get something in that exact format that can be written to a text file.

This gets me my final database! Now i just chuck the database.js online and the index.html and all of the documents on olindocs.com in the home directory. (I won't push the html on people, but I encourage the interested to look at the source code of olindocs; it's mostly iteration and is fairly easy to understand.)

No comments: