#!/usr/bin/python # Filename: GroupToBookmark.py # Author:huyoo,http://blog.csdn.net/huyoo import os newline=os.linesep def listtolinks(l): suojin=0 #indent suojin+=4 ltime=l[1].split('huyoo') atim=ltime[2] mtim=ltime[1] ctim=ltime[0] linkstr=""*suojin+'<DT><H3 FOLDED ADD_DATE="'+ctim+'">'+l[0]+'</H3>'+newline linkstr+=""*suojin+"<DL><p>"+newline suojin+=4 for a in range(1,len(l)/2): if l[a*2+1]=="#": pass#linkstr+='<dt>'+l[a*2]+'</dt>'+newline else: linkstr+=""*suojin+'<DT><A HREF="'+l[a*2+1]+'" ADD_DATE="'+ctim+'" LAST_VISIT="'+atim+'" LAST_MODIFIED="'+mtim+'">'+l[a*2]+'</A>'+newline suojin-=4 linkstr+=""*suojin+"</DL><p>"+newline suojin-=4 return linkstr l=[] fl=[] fo=file('order.txt') while True: line=fo.readline() if len(line)==0: break line=line.rstrip() fl.append(line) fo.close() def filetolist(fname,l): statinfo=os.stat(fname) tmpstr="huyoo".join([str(int(statinfo.st_ctime)),str(int(statinfo.st_mtime)),str(int(statinfo.st_atime))]) #print tmpstr l.append(tmpstr) f = file(fname) while True: line = f.readline() if len(line) == 0: break line=line.rstrip() l.append(line) f.close() for it in l: if it[0:3]=="dow"or it[0:3]=="[Gr": l.remove(it) for a in range(0,len(l)): ti=l[a][:] ti=ti[ti.find("=")+1:] #print ti l[a]=ti hcode="" for e in fl: l+=["="*35+e+"="*35,"#"] tmpl=[e[:-4]] filetolist(e,tmpl) hcode+=listtolinks(tmpl) l+=tmpl[:] headstr="""<!DOCTYPE NETSCAPE-Bookmark-file-1> <!-- This is an automatically generated file. It will be read and overwritten. Do Not Edit! --> <TITLE>Bookmarks</TITLE> <H1>Bookmarks</H1> <DL><p> """ tailstr="<DL><p>" navfile=file("bookmark.htm",'w') navfile.write(headstr+hcode+tailstr) navfile.close() print"done!!!"