#!/usr/bin/env python # # Script to backup all of your Roller resources. # # Usage: # get_files.py /export/home/richb/Blog/Backup/resources/uploadFiles.do.html # import os import string import sys import tempfile def runCommand(command): outfile = tempfile.mktemp() errfile = tempfile.mktemp() cmd = "( %s ) > %s 2> %s" % (command, outfile, errfile) err = os.system(cmd) >> 8 try: if err != 0: raise RuntimeError, '%r failed with exit code %d\n%s' % ( command, err, file(errfile).read()) return file(outfile).read() finally: os.remove(outfile) os.remove(errfile) def main(file): username = "richb" password = "XXXXXXXX" starting = False input_file = open(file) for s in input_file: if s.find("Manage Uploaded Files") != -1: starting = True if s.find("Powered by") != -1: starting = False if starting and s.find("a href=") != -1: startOff = s.find("\"") + 1 endOff = s.find("\"", startOff) file = s[startOff:endOff] print "Found file: `%s`" % file command = "wget -r --user=%s --password=%s -np %s" % \ (username, password, file) runCommand(command) if __name__ == "__main__": sys.exit(main(sys.argv[1]))