Beispiel #1
0
        else:
            if args.month:
                ocs.set_month(args.month)
                crits.append('\n\tmonth %s' % args.month)
            if args.year:
                ocs.set_year(args.year)
                crits.append('\n\tyear %s' % args.year)

        print("Searching Ofgem for certificates matching:{}\n".format(", ".join(crits)))
        ocs.get_data()
    else:
        ocs = CertificateSearch(filename=args.filename)

    print("Total of %d records returned" % len(ocs))

    if args.output is None:
        for station in ocs.stations():
            print("{:16s}: {}".format(to_string(station, 'generator_id'), to_string(station, 'name')))
            for c in station.certs:
                print(c.as_string() if args.verbose else str(c))
            print("\n")

    else:
        with open(args.output, 'wt') as csvfile:
            csv_writer = csv.writer(csvfile, quoting=csv.QUOTE_NONNUMERIC)
            csv_writer.writerow(CertificateStation.csv_title_row())
            for s in ocs.stations():
                csv_writer.writerows(s.as_csvrow())
        print("Output saved to file {} [CSV]".format(args.output))