Exemplo n.º 1
0
def scrape(election):
    print("Scraping results for %s county" % election.county)
    election.scrape_results()

    print "Writing json."
    write_json(election.results)

    print "Writing html."
    write_html(election.county, election.results)
Exemplo n.º 2
0
if __name__ == "__main__":
    parser = optparse.OptionParser()
    parser.add_option("-l", "--loop", dest="loop",
                      action="store_true", default=False,
                      help="run in a loop (infinitely)")
    parser.add_option("-i", "--interval", dest="interval",
                      default=120,
                      help="number of seconds to sleep between runs")
    options, args = parser.parse_args()

    try:
        float(options.interval)
    except TypeError as e:
        print "Interval *must* be a number, not '", options.interval, "'"
        sys.exit(1)

    print "Reading data"
    DATA = initial_read()
    while True:
        print "Scraping results"
        DATA = scrape_results(DATA)

        print "Writing file(s)."
        HTML = write_html(DATA)

        if not options.loop:
            break

        print "Sleeping for", options.interval, "seconds"
        sleep(float(options.interval))