def process(path): if not os.path.exists(path): print '%s not exists' % path return if os.path.isfile(path): return process_file(path) for dir_path, subpaths, filenames in os.walk(path): for filename in filenames: process_file(os.path.join(dir_path, filename)) if __name__ == '__main__': parser = OptionParser() parser.add_option('-i', "--input", dest="path", help="input file, or path") parser.add_option("-l", "--list", action="store_true", dest="list_stories", default=False, help="list stories") parser.add_option("-p", "--parse", action="store_true", dest="parse_stories", default=False, help="parse stories from input") (options, args) = parser.parse_args() if options.parse_stories: process(options.path) elif options.list_stories: stories = Story.get_all() for story in stories: if not story.url: print '-' * 80 print 'no link'