#----------------------------------------------------------------------------- # Name: bookmarker.py # Purpose: A bookmark generator with collapse/expand formatting # # Author: Mark Langenhoven # # Created: 2005/02/05 # RCS-ID: $Id: bookmarker.py $ # Copyright: (c) 2005 # Licence: GPL # # Revisions #----------------------------------------------------------------------------- #!/usr/bin/env python #Boa:PyApp:main modules ={} import sys, string def main(): """Get the command line parameters to read in the text data or pull in bookmarks.txt if nothing is specified.""" if sys.argv[1:]: #Open up input file infile = open(sys.argv[1], "r") #Read the file into a list inlist = [] inlist = infile.readlines() infile.close() else: #Open up the default file infile = open('bookmarks.txt', "r") inlist = [] inlist = infile.readlines() infile.close() grouplist = [] #Break each line down into it's various components for line in inlist: line = string.strip(line) if line != '': #Split the line up into it's various components tmplist = [] tmplist = string.split(line, ' ',1) grouplist.append(tmplist) #Now create the output file makefile(grouplist) def makefile(thelist): """Produce the final bookmarks.html file with all the data from the input file as well as the associated cookies.js file""" outfile = open('bookmarks.htm', "w") #Put in the heading part of the file outfile.write('\n') outfile.write('Bookmarks\n') outfile.write('\n') outfile.write('\n') outfile.write('\n') outfile.write('\n') outfile.write('\n') outfile.write('\n') outfile.write('\n') #Create the body of the file outfile.write('\n') outfile.write('\n') #Do the stuff in the lefthand column first #We fill it like this so that the two first groups in the file #are the top two boxes on the page colcount = 1 outfile.write('
\n') for line in thelist: if line[0] == 'G:': groupstuff = string.split(line[1],' ',1) if colcount % 2 != 0: outfile.write('
\n') outfile.write('
\n') colcount = colcount + 1 outfile.write('
\n') #Do the stuff in the righthand column colcount = 1 outfile.write('
\n') for line in thelist: if line[0] == 'G:': groupstuff = string.split(line[1],' ',1) if colcount % 2 == 0: outfile.write('
\n') outfile.write('
\n') colcount = colcount + 1 outfile.write('
\n') #Finish off the file outfile.write('\n\n') outfile.close() if __name__ == '__main__': main()