Esempio n. 1
0
def main():
    parser = commandline_parser(
        'Get ofgem certificates for a given month & year')
    parser.add_argument('--generator',
                        action='store',
                        help='Generator ID to search for')

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

    print("Contacting Ofgem and preparing to search.\n")
    ocs = CertificateSearch()
    ocs.start()
    print("Filtering search:")

    if args.station:
        print("    - cannot filter results based on station name")

    if args.scheme:
        if ocs.filter_scheme(args.scheme):
            print("    - scheme {}".format(args.scheme))
        else:
            print("\nFailed to filter for scheme.")
            sys.exit(0)

    if args.generator:
        if ocs.filter_generator_id(args.generator.upper()):
            print("    - generator id  {}".format(args.generator.upper()))
        else:
            print("\nFailed to filter by generator")
            sys.exit(0)

    if args.period:
        if ocs.set_period(args.period):
            print('    - period should be {}'.format(args.period))
        else:
            print("\nFailed to set period")
            sys.exit(0)

    if ocs.get_data() is False:
        print("No data was returned from the Ofgem server")
        sys.exit(0)

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

    fmt = StdoutFormatter("10s", "8s", "35s", "6s", "10s", "12d")
    print(
        fmt.titles("Issue Date", "Period", "Station Name", "Scheme", "Status",
                   "Certificates"))
    for cert in ocs.certificates():
        print(
            fmt.row(cert.issue_dt.strftime("%Y-%m-%d"), cert.period, cert.name,
                    cert.scheme, cert.status, cert.certificates))
def main():
    parser = commandline_parser('Get ofgem certificates for a given month & year')
    parser.add_argument('--generator', action='store', help='Generator ID to search for')

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

    print("Contacting Ofgem and preparing to search.\n")
    ocs = CertificateSearch()
    ocs.start()
    print("Filtering search:")

    if args.station:
        print("    - cannot filter results based on station name")

    if args.scheme:
        if ocs.filter_scheme(args.scheme):
            print("    - scheme {}".format(args.scheme))
        else:
            print("\nFailed to filter for scheme.")
            sys.exit(0)

    if args.generator:
        if ocs.filter_generator_id(args.generator.upper()):
            print("    - generator id  {}".format(args.generator.upper()))
        else:
            print("\nFailed to filter by generator")
            sys.exit(0)

    if args.period:
        if ocs.set_period(args.period):
            print('    - period should be {}'.format(args.period))
        else:
            print("\nFailed to set period")
            sys.exit(0)

    if ocs.get_data() is False:
        print("No data was returned from the Ofgem server")
        sys.exit(0)

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

    fmt = StdoutFormatter("10s", "8s", "35s", "6s", "10s", "12d")
    print(fmt.titles("Issue Date", "Period", "Station Name", "Scheme", "Status", "Certificates"))
    for cert in ocs.certificates():
        print(fmt.row(cert.issue_dt.strftime("%Y-%m-%d"),
                      cert.period,
                      cert.name,
                      cert.scheme,
                      cert.status,
                      cert.certificates))
Esempio n. 3
0
def main():
    """ Main command line function.
    """
    build_command_names()
    parser = commandline_parser(
        "pywind command line app, version {}".format(__version__),
        epilog=commands_help())
    parser.add_argument('command',
                        nargs='?',
                        help='Command to execute (see below for list)')
    args = parser.parse_args()

    if args.version:
        print("pywind version {}".format(__version__))
        sys.exit(0)

    if args.apikey is not None and os.path.exists(args.apikey):
        print("Reading API Key from {}".format(args.apikey))
        with open(args.apikey, 'r') as apifh:
            args.apikey = apifh.read().strip()

    cmd = COMMAND_NAMES.get(args.command, None)
    if cmd is None:
        if args.command is not None:
            print("Invalid command specified: {}".format(args.command))
        print(commands_help())
        sys.exit(0)

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

    print("\n{}\n{}\n".format(cmd['name'], "=" * len(cmd['name'])))
    obj = cmd['function'](args)

    if args.save:
        filename = args.original or args.command
        if hasattr(obj, 'save_original'):
            if obj.save_original(filename) is False:
                print("Unable to save the downloaded data :-(")
            else:
                print("Downloaded data saved to {}".format(filename))
        else:
            print("Saving data is not supported for this command.")

    if args.export is not None:
        export_to_file(args, obj)
Esempio n. 4
0
def main():
    """ Main command line function.
    """
    build_command_names()
    parser = commandline_parser("pywind command line app, version {}".format(__version__),
                                epilog=commands_help())
    parser.add_argument('command', nargs='?', help='Command to execute (see below for list)')
    args = parser.parse_args()

    if args.version:
        print("pywind version {}".format(__version__))
        sys.exit(0)

    cmd = COMMAND_NAMES.get(args.command, None)
    if cmd is None:
        if args.command is not None:
            print("Invalid command specified: {}".format(args.command))
        print(commands_help())
        sys.exit(0)

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

    print("\n{}\n{}\n".format(cmd['name'], "=" * len(cmd['name'])))
    obj = cmd['function'](args)

    if args.save:
        filename = args.original or args.command
        if hasattr(obj, 'save_original'):
            if obj.save_original(filename) is False:
                print("Unable to save the downloaded data :-(")
            else:
                print("Downloaded data saved to {}".format(filename))
        else:
            print("Saving data is not supported for this command.")

    if args.export is not None:
        export_to_file(args, obj)
Esempio n. 5
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')))
Esempio n. 6
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')))