#! /usr/bin/env python import os, sys, datetime home = os.getenv("HOME") droidurls = '/droidsd/feeds/saved-urls' #rssfile = os.path.join(home, ".plucker/html/xtraurls.rss") rssfile = os.path.join(home, "feeds/xtraurls.rss") urlarchive = os.path.join(home, "Docs/Lists/xtraurls.html") ifp = None ofp = None archivefp = None try : ifp = open(droidurls, "r") except : print "No urls to back up" try : os.unlink(rssfile) except : pass sys.exit(0) numurls = 0 while 1 : line = ifp.readline().strip() # Remove newline, as well as any spaces if not line : break if line == '' : continue # If this is the first one, we need to open output files if numurls == 0 : # Remove the old rss file if there is one: try : os.unlink(rssfile) except : pass ofp = open(rssfile, "w") print >>ofp, """ FeedMe URLs Plucker Saved URLs en""" try : archivefp = open(urlarchive, "a") print >>archivefp, "

Feedme URLs %s

" \ % datetime.datetime.now().ctime() except : pass numurls += 1 print >>ofp, """ %s %s %s """ % (line, line, line) if archivefp : print >>archivefp, "%s" % (line, line) print >>ofp, """
""" ifp.close() ofp.close() if archivefp : archivefp.close() # If we got this far, we've retrieved the URLs, so clear the file. # Eventually we should just unlink, but for now, lets be save and # keep a backup: os.system("cat %s >>%s/feeds/droidurls" % (droidurls, home)) os.unlink(droidurls) if numurls > 0 : print "Saved %s urls to %s" % (numurls, rssfile)