Beispiel #1
0
    print "\n\n\f"
  except IOError:
    sys.exit(0) # broken stdout => broken pipe
  except Exception as e:
    sys.stderr.write("\nError extracting article: " + str(e) + "\n")

if __name__ == "__main__":
  try:
    parser = OptionParser(usage="usage: %s [-d output-directory] <stdin>" % sys.argv[0])
    parser.add_option("-d",
                      action="store", type="string", dest="directory",
                      help="directory where to store the articles")
    (options, args) = parser.parse_args()

    if len(args) > 0:
      print parser.usage
      exit(1)

    htmlparser = HTMLParser.HTMLParser()
    if options.directory != None:
      do_article = lambda a: save_article(htmlparser, a, options.directory)
    else:
      do_article = lambda a: print_article(htmlparser, a)

    parser = WikiParser(do_article)
    parser.process()
    parser.close()
  except KeyboardInterrupt:
    sys.stderr.write("\n\nCancelled. Partial results may have been generated.\n")
    exit(1)