Beispiel #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))
Beispiel #3
0
                continue

            # Write name
            ws.write_merge(PERIOD_START - 4, PERIOD_START - 4, col, col + 4,
                           station.name, title_style)
            # add accreditation #
            if scheme == 'RO':
                ws.write_merge(PERIOD_START - 2, PERIOD_START - 2, col, col + 4,
                               'RO: ' + station.accreditation + '  [' + station.commission_dt.strftime("%d %b %Y") + ']',
                               title_style)
            elif scheme == 'REGO':
                ws.write_merge(PERIOD_START - 3, PERIOD_START - 3, col, col + 4,
                               'REGO: ' + station.accreditation + '  [' + station.commission_dt.strftime("%d %b %Y") + ']',
                               title_style)

            cs = CertificateSearch()

            cs.set_scheme(scheme)
            cs.set_start_month(start_month)
            cs.set_start_year(start_year)
            cs.set_finish_month(end_month)
            cs.set_finish_year(end_year)
            cs.accreditation = station.accreditation

            if not cs.get_data():
                print "Unable to get any certificate data :-("
                continue

            data = {}
            for c in cs.certificates:
#                print c.as_string()
Beispiel #4
0
def main():
    """ Function that actually does the work :-) """
    parser = commandline_parser('Download bulk information from Ofgem to produce an Excel spreadsheet')
    parser.add_argument('start', type=int, help='Period to start (YYYYMM)')
    parser.add_argument('end',  type=int, help='Period to finish (YYYYMM)')
    parser.add_argument('--filename',
                        default='certificates.xls',
                        help='Filename to export to')
    parser.add_argument('--stations', nargs='*', help='Stations to search for')
    args = parser.parse_args()
    print(args)

    if not args.filename.endswith('.xls'):
        args.filename += '.xls'

    periods = []
    start_dt = _convert_type(args.start, 'period')
    end_dt = _convert_type(args.end, 'period')
    for yyy in range(start_dt.year, end_dt.year + 1):
        mmm = start_dt.month if start_dt.year == yyy else 1
        mm2 = end_dt.month if end_dt.year == yyy else 12
        for mon in range(mmm, mm2+1):
            periods.append(date(yyy, mon, 1))

    print("Period covered will be {} to {}. A total of {} periods".
          format(start_dt.strftime("%b-%Y"),
                 end_dt.strftime("%b-%Y"),
                 len(periods)))

    stations = []
    station_names = args.stations or []

    if args.input is not None:
        with open(args.input) as fh:
            for line in fh.readlines():
                station = line.strip()
                if '#' in station:
                    (station, dummy_junk) = station.split('#', 1)
                station_names.append(station)

    if len(station_names) > 0:
        print("Station names to be searched for:")
        for stat in station_names:
            print("    - {}".format(stat))

    while True:
        station = raw_input("Enter a station name (or blank to finish)")
        if station.strip() == '':
            break
        if ',' in station:
            for s in station.strip().split(','):
                station_names.append(s)
        else:
            station_names.append(station)

    if len(station_names) == 0:
        print("No stations to process. Exiting...")
        sys.exit(0)

    print("\nSearching for stations...")
    for name in station_names:
        print("    - {}".format(name))
        sss = StationSearch()
        sss.start()
        if sss.filter_name(name) and sss.get_data():
            stations.extend(sss.stations)
            print("        found")
        else:
            print("        no stations found")

    print("A total of {} stations will be recorded".format(len(stations)))

    wbb = Workbook()
    add_station_sheet(wbb, stations)

    print("\nGetting certificate data (this is quicker)...")
    certificates = {}
    for station in stations:
        print("    - {}".format(station.name))
        ocs = CertificateSearch()
        ocs.start()
        if ocs.filter_generator_id(station.generator_id) and \
                ocs.set_start_month(start_dt.month) and \
                ocs.set_start_year(start_dt.year) and \
                ocs.set_finish_month(end_dt.month) and \
                ocs.set_finish_year(end_dt.year) and \
                ocs.get_data():
            certificates[station.name] = ocs.cert_list
            add_certificate_sheet(wbb, station, ocs.certificates)
            print("        added to spreadsheet")
        else:
            print("        nothing to add")

    wbb.save(args.filename)
    print("\nData saved to {}".format(args.filename))
Beispiel #5
0
def test(theseargs):

    parser = argparse.ArgumentParser(description='Extract monthly data for supplied year for Hydro or Biogas stations.')
    parser.add_argument('--year',
                        action='store',
                        type=int,
                        default=date.today().year - 1,
                        help='Year to extract data for')
    parser.add_argument('--technology', nargs='*')

    args = parser.parse_args(args=theseargs)

    if args.technology is None:
        print("You must specify at least one technology group")
        sys.exit(0)
    print("  Searching year %d \n" % args.year)
    tids = []
    fn = "_".join(args.technology) + "_%d.csv" % args.year
    print(fn)
    for t in args.technology:
        for poss in TECHNOLOGY_LIST:
            if t.lower() in poss.lower():
                tids.append(TECHNOLOGY_LIST[poss])
                print("  Filter will match technology "+ poss)

    cs = CertificateSearch()
    cs.set_start_year(args.year)
    cs.set_finish_year(args.year)
    cs.set_start_month(1)
    cs.set_finish_month(12)
    cs.scheme = 1

    print("\n\nSearching for certificates...")
    cs.get_data()
    print("\n Complete.\n\nTotal of %d records to be filtered" % len(cs))
    added = 0
    if sys.version_info.major > 2:
        csvfile = open(fn, 'w', newline='')
    else:
        csvfile = open(fn, 'wb')
    spamwriter = csv.writer(csvfile, delimiter=',',
                            quotechar='"', quoting=csv.QUOTE_MINIMAL)
    spamwriter.writerow([x.capitalize() for x in cs.certificates[0].FIELDS])
    for c in cs.certificates:
        for t in args.technology:
            if t.lower() in c.technology.lower():
                spamwriter.writerow(c.as_list())
                added += 1
    csvfile.close()
    print("Filtering complete. %d records saved as %s" % (added, fn))
Beispiel #6
0
def test(theseargs):

    parser = argparse.ArgumentParser(description='Download bulk information from Ofgem to produce an Excel spreadsheet')
    parser.add_argument('--start', action='store', required=True, help='Period to start from (MMM-YYYY)')
    parser.add_argument('--end', action='store', required=True, help='Period to finish on (MMM-YYYY)')
    parser.add_argument('--scheme', action='store', default='RO', help='Scheme to get certificates for')
    parser.add_argument('--filename', action='store', default='certificates.xls', help='Filename to export to')
    parser.add_argument('--name', action='store', default=None, help='Part of a name of generation station (or name fragments for several stations, separated by commas)')
    args = parser.parse_args(args=theseargs)

    (start_year, start_month) = get_period(args.start)
    (end_year, end_month) = get_period(args.end)
    if not args.filename.endswith('.xls'):
        args.filename += '.xls'

    periods = []
    for yy in range(start_year, end_year + 1):
        mm = start_month if start_year == yy else 1
        mm2 = end_month if end_year == yy else 12
        for m in range(mm, mm2+1):
            periods.append(date(yy,m,1).strftime("%b-%Y"))

    station = args.name
    if station is None:
        stations = []
        while (True):
            station = input("Enter a station name (or blank to finish)")
            if station.strip() == '':
                break
            if ',' in station:
                for s in station.strip().split(','):
                    s = s.strip()
                    if s in stations:
                        continue
                    stations.append(s)
            else:
                station = station.strip()
                if station in stations:
                    continue
                stations.append(station)
    else:
        stations = station.strip().split(',')
        
    if len(stations) == 0:
        print("No stations to process. Exiting...")
        sys.exit(0)

    wb = Workbook()
    ws = wb.add_sheet('Certificate Data', cell_overwrite_ok=True)
    ws.write(PERIOD_START - 1,0,"Period")
    for i in range(0, len(periods)):
        ws.write(PERIOD_START + i, 0, periods[i])

    al = Alignment()
    al.horz = Alignment.HORZ_CENTER
    al.vert = Alignment.VERT_CENTER

    title_style = XFStyle()
    title_style.alignment = al

    print("\nTotal of %d stations to process\n" % len(stations))
    for i in range(0, len(stations)):
        s = stations[i]
        col = 1 + 5 * i
        print("    "+ s)

        # add headers
        ws.write(PERIOD_START - 1, col, "Installed Capacity")
        ws.write(PERIOD_START - 1, col + 1, "RO Certificates")
        ws.write(PERIOD_START - 1, col + 2, "RO Factor")
        ws.write(PERIOD_START - 1, col + 3, "REGO Certificates")
        ws.write(PERIOD_START - 1, col + 4, "REGO Factor")

        capacity = {}
        for scheme in ['RO','REGO']:
            offset = 1 if scheme == 'RO' else 3
            ss = StationSearch()
            ss.filter_scheme(scheme)
            ss.filter_name(s)
            if not ss.get_data():
                print("Unable to find any station with a name %s" % s)
                continue

            station = None
            # if more than one generator has matched, use the first WIND one 
            if len(ss.stations) > 1:
                print('Several stations found that match %s:' % s)
                print(list(st.name for st in ss.stations))
                print('The first wind station will be selected')
                for st in ss.stations:
                    if 'wind' in st.technology.lower():
                        station = st
                        break
            else:
                station = ss.stations[0]

            if station is None:
                print("Unable to get station data for '%s'" % s)
                continue

            # Write name
            ws.write_merge(PERIOD_START - 4, PERIOD_START - 4, col, col + 4,
                           station.name, title_style)
            # add accreditation #
            if scheme == 'RO':
                ws.write_merge(PERIOD_START - 2, PERIOD_START - 2, col, col + 4,
                               'RO: ' + station.accreditation + '  [' + station.commission_dt.strftime("%d %b %Y") + ']',
                               title_style)
            elif scheme == 'REGO':
                ws.write_merge(PERIOD_START - 3, PERIOD_START - 3, col, col + 4,
                               'REGO: ' + station.accreditation + '  [' + station.commission_dt.strftime("%d %b %Y") + ']',
                               title_style)
            cs = CertificateSearch()

            cs.set_start_month(start_month)
            cs.set_start_year(start_year)
            cs.set_finish_month(end_month)
            cs.set_finish_year(end_year)
            cs.filter_accreditation(station.accreditation)
            #cs.filter_scheme(scheme) # seems to work ok without this, and REGOs break with it
            #cs.filter_status(['Issued','Redeemed','Expired']) # this doesn't work. And arguable whether expired should count
            
            if not cs.get_data():
                print("Unable to get any certificate data :-(")
                continue

            data = {}
            for c in cs.certificates:
                # print(c.as_string())
                if c.status in ['Revoked','Retired','Expired']:
                    continue

                row = periods.index(c.period) + PERIOD_START
                if not c.period in capacity:
                    ws.write(row, col, c.capacity)
                    capacity[c.period] = True

                data[c.period] = data.get(c.period,0) + c.certs
                ws.write(row, col + offset + 1, c.factor)

            for p,val in viewitems(data):
                row = periods.index(p) + PERIOD_START
                ws.write(row, col + offset, val)

    print("\nComplete. Excel spreadsheet %s" % args.filename)
    wb.save(args.filename)
Beispiel #7
0
        #        if scheme == 'RO':
        #            ws.write_merge(PERIOD_START - 2,
        #                           PERIOD_START - 2,
        #                           col,
        #                           col + 4,
        #                           'RO: ' + station.accreditation + '  [' + station.commission_dt.strftime("%d %b %Y") + ']',
        #                           title_style)
        #        elif scheme == 'REGO':
        #            ws.write_merge(PERIOD_START - 3,
        #                           PERIOD_START - 3,
        #                           col,
        #                           col + 4,
        #                           'REGO: ' + station.accreditation + '  [' + station.commission_dt.strftime("%d %b %Y") + ']',
        #                           title_style)

        cs = CertificateSearch()
        cs.set_start_month(start_month)
        cs.set_start_year(start_year)
        cs.set_finish_month(end_month)
        cs.set_finish_year(end_year)

        #        print dir(cs)
        #        print dir(cs.form)
        #        print cs.form.fields
        cs.form.set_text_value('accreditation', station.accreditation)

        if not cs.get_data():
            print "Unable to get any certificate data :-("
            continue
#        print cs.certificates
#        continue
Beispiel #8
0
def main():
    """ Function that actually does the work :-) """
    parser = commandline_parser(
        'Download bulk information from Ofgem to produce an Excel spreadsheet')
    parser.add_argument('start', type=int, help='Period to start (YYYYMM)')
    parser.add_argument('end', type=int, help='Period to finish (YYYYMM)')
    parser.add_argument('--filename',
                        default='certificates.xls',
                        help='Filename to export to')
    parser.add_argument('--stations', nargs='*', help='Stations to search for')
    args = parser.parse_args()
    print(args)

    if not args.filename.endswith('.xls'):
        args.filename += '.xls'

    periods = []
    start_dt = _convert_type(args.start, 'period')
    end_dt = _convert_type(args.end, 'period')
    for yyy in range(start_dt.year, end_dt.year + 1):
        mmm = start_dt.month if start_dt.year == yyy else 1
        mm2 = end_dt.month if end_dt.year == yyy else 12
        for mon in range(mmm, mm2 + 1):
            periods.append(date(yyy, mon, 1))

    print("Period covered will be {} to {}. A total of {} periods".format(
        start_dt.strftime("%b-%Y"), end_dt.strftime("%b-%Y"), len(periods)))

    stations = []
    station_names = args.stations or []

    if args.input is not None:
        with open(args.input) as fh:
            for line in fh.readlines():
                station = line.strip()
                if '#' in station:
                    (station, dummy_junk) = station.split('#', 1)
                station_names.append(station)

    if len(station_names) > 0:
        print("Station names to be searched for:")
        for stat in station_names:
            print("    - {}".format(stat))

    while True:
        station = raw_input("Enter a station name (or blank to finish)")
        if station.strip() == '':
            break
        if ',' in station:
            for s in station.strip().split(','):
                station_names.append(s)
        else:
            station_names.append(station)

    if len(station_names) == 0:
        print("No stations to process. Exiting...")
        sys.exit(0)

    print("\nSearching for stations...")
    for name in station_names:
        print("    - {}".format(name))
        sss = StationSearch()
        sss.start()
        if sss.filter_name(name) and sss.get_data():
            stations.extend(sss.stations)
            print("        found")
        else:
            print("        no stations found")

    print("A total of {} stations will be recorded".format(len(stations)))

    wbb = Workbook()
    add_station_sheet(wbb, stations)

    print("\nGetting certificate data (this is quicker)...")
    certificates = {}
    for station in stations:
        print("    - {}".format(station.name))
        ocs = CertificateSearch()
        ocs.start()
        if ocs.filter_generator_id(station.generator_id) and \
                ocs.set_start_month(start_dt.month) and \
                ocs.set_start_year(start_dt.year) and \
                ocs.set_finish_month(end_dt.month) and \
                ocs.set_finish_year(end_dt.year) and \
                ocs.get_data():
            certificates[station.name] = ocs.cert_list
            add_certificate_sheet(wbb, station, ocs.certificates)
            print("        added to spreadsheet")
        else:
            print("        nothing to add")

    wbb.save(args.filename)
    print("\nData saved to {}".format(args.filename))
Beispiel #9
0
#! /usr/bin/env python
# coding=utf-8
#
# Copyright 2013 david reid <*****@*****.**>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from pywind.ofgem import CertificateSearch
cs = CertificateSearch()
cs.set_month(1)
cs.set_year(2012)
cs.filter_technology('off-shore')
cs.get_data()
print(str(len(cs))+' certificates found. This is the first: ')
print(cs.certificates[0].as_string())
Beispiel #10
0
        #        if scheme == 'RO':
        #            ws.write_merge(PERIOD_START - 2,
        #                           PERIOD_START - 2,
        #                           col,
        #                           col + 4,
        #                           'RO: ' + station.accreditation + '  [' + station.commission_dt.strftime("%d %b %Y") + ']',
        #                           title_style)
        #        elif scheme == 'REGO':
        #            ws.write_merge(PERIOD_START - 3,
        #                           PERIOD_START - 3,
        #                           col,
        #                           col + 4,
        #                           'REGO: ' + station.accreditation + '  [' + station.commission_dt.strftime("%d %b %Y") + ']',
        #                           title_style)

        cs = CertificateSearch()
        cs.set_start_month(start_month)
        cs.set_start_year(start_year)
        cs.set_finish_month(end_month)
        cs.set_finish_year(end_year)

        #        print dir(cs)
        #        print dir(cs.form)
        #        print cs.form.fields
        cs.form.set_text_value("accreditation", station.accreditation)

        if not cs.get_data():
            print "Unable to get any certificate data :-("
            continue
        #        print cs.certificates
        #        continue