Ejemplo n.º 1
0
def main():
    parser = commandline_parser('Search ofgem database for matching stations')
    parser.add_argument('--generator',
                        action='store',
                        help='Generator ID to search for')
    parser.add_argument('--organisation',
                        action='store',
                        help='Organisation to search for')

    args = parser.parse_args()

    if args.station is None and \
                    args.generator is None and \
                    args.organisation is None:
        print("You must specify either a name, generator id or organisation")
        sys.exit(0)

    setup_logging(args.debug, request_logging=args.request_debug)

    print("Connecting with Ofgem website and preparing the search...")
    osd = StationSearch()
    osd.start()

    print("Setting up filters:")

    if args.station is not None:
        osd.filter_name(args.station)
        print("    - station name contains {}".format(args.station))

    if args.organisation:
        osd.filter_organisation(args.organisation)
        print("    -  organisation contains {}".format(args.organisation))

    if args.generator:
        if args.generator.upper()[0] in ['R', 'P']:
            osd.filter_scheme('RO')
        elif args.generator.upper()[0] == 'G':
            osd.filter_scheme('REGO')
        osd.filter_generator_id(args.generator.upper())
        print("    - generator ID is {}".format(args.generator.upper()))

    print("\nGetting results from Ofgem...\n")

    if osd.get_data() is False:
        print("Search returned no data")
        sys.exit(0)

    print("Query returned {} result{}".format(len(osd),
                                              '' if len(osd) == 0 else 's'))

    fmt = StdoutFormatter("35s", "13s", "12.2f", "20s", "20s", "15s")
    print(
        fmt.titles("Station Name", "Commission Dt", "Capacity", "Technology",
                   "Country", "Generator ID"))

    for stat in osd.rows():
        # The rows() output is intended for exporting, so fields will have '@' prepended
        # if they are attributes.
        # This could also be done by using osd.stations
        station = stat.get('Station')
        if station is None:
            continue
        cdt = station.get('@commission_dt')
        print(
            fmt.row(station.get('@name'),
                    cdt.strftime("%Y-%m-%d") if cdt else 'n/a',
                    station.get('@capacity'), station.get('@technology'),
                    station.get('@country'), station.get('@generator_id')))
Ejemplo n.º 2
0
    osd.filter_scheme(args.scheme)

    if args.name:
        osd.filter_name(args.name)
        crit += "\n\tname contains '%s'" % args.name

    if args.organisation:
        osd['organisation'] = args.organisation
        crit += "\n\torganisation is '%s'" % args.organisation

    if args.generator:
        if args.generator.upper()[0] == 'R':
            osd.filter_scheme('RO')
        elif args.generator.upper()[0] == 'G':
            osd.filter_scheme('REGO')
        osd.filter_generator_id(args.generator.upper())
        crit += "\n\tgenerator ID is '%s' [also forces scheme]" % args.generator.upper(
        )

    print(crit)
    print("\nGetting results from Ofgem...\n")
    if osd.get_data():
        print("Query returned {} result{}".format(
            len(osd), '' if len(osd) == 0 else 's'))

        if args.output is None:
            for s in osd.stations:
                print(s.as_string() + "\n")
        else:
            output_fn = args.output
            if '.' not in output_fn:
Ejemplo n.º 3
0
def main():
    parser = commandline_parser('Search ofgem database for matching stations')
    parser.add_argument('--generator', action='store', help='Generator ID to search for')
    parser.add_argument('--organisation', action='store', help='Organisation to search for')

    args = parser.parse_args()

    if args.station is None and \
                    args.generator is None and \
                    args.organisation is None:
        print("You must specify either a name, generator id or organisation")
        sys.exit(0)

    setup_logging(args.debug, request_logging=args.request_debug)

    print("Connecting with Ofgem website and preparing the search...")
    osd = StationSearch()
    osd.start()

    print("Setting up filters:")

    if args.station is not None:
        osd.filter_name(args.station)
        print("    - station name contains {}".format(args.station))

    if args.organisation:
        osd.filter_organisation(args.organisation)
        print("    -  organisation contains {}".format(args.organisation))

    if args.generator:
        if args.generator.upper()[0] in ['R', 'P']:
            osd.filter_scheme('RO')
        elif args.generator.upper()[0] == 'G':
            osd.filter_scheme('REGO')
        osd.filter_generator_id(args.generator.upper())
        print("    - generator ID is {}".format(args.generator.upper()))

    print("\nGetting results from Ofgem...\n")

    if osd.get_data() is False:
        print("Search returned no data")
        sys.exit(0)

    print("Query returned {} result{}".format(len(osd), '' if len(osd) == 0 else 's'))

    fmt = StdoutFormatter("35s", "13s", "12.2f", "20s", "20s", "15s")
    print(fmt.titles("Station Name", "Commission Dt", "Capacity",
                     "Technology", "Country", "Generator ID"))

    for stat in osd.rows():
        # The rows() output is intended for exporting, so fields will have '@' prepended
        # if they are attributes.
        # This could also be done by using osd.stations
        station = stat.get('Station')
        if station is None:
            continue
        cdt = station.get('@commission_dt')
        print(fmt.row(station.get('@name'),
                      cdt.strftime("%Y-%m-%d") if cdt else 'n/a',
                      station.get('@capacity'),
                      station.get('@technology'),
                      station.get('@country'),
                      station.get('@generator_id')))