コード例 #1
0
ファイル: api.py プロジェクト: BenPortner/pywind
    def get_data(self, **params):
        """ Get data from the Elexon servers and attempt to parse it into a series of
            dicts each representing a record. Parameters are passed as a dict.
            Multiple sets of data are created in the multi member, single sets in items.
        """
        if self.report is None:
            raise Exception(
                "ElexonAPI objects require the report be set before use.")
        if self.apikey is None:
            raise Exception(
                "An API key is required to use the Elexon API accessor functionality"
            )

        url = make_elexon_url(self.report, self.version)
        params.update({'APIKey': self.apikey, 'ServiceType': 'xml'})
        req = get_or_post_a_url(url, params=params)
        #        print(req.content)
        xml = parse_response_as_xml(req)
        http = xml.xpath('/response/responseMetadata/httpCode')
        response_code = int(http[0].text)
        if response_code == 204:
            print("No content returned, but no error reported.")
            return True
        elif response_code != 200:
            print("No data returned. Error reported.")
            err = xml.xpath('/response/responseMetadata/description')
            print(err[0].text)
            return False

        if self.MULTI_RESULTS is None:
            for item in xml.xpath('/response/responseBody/responseList/item'):
                item_dict = map_xml_to_dict(item, self.XML_MAPPING)

                if 'activeflag' in item_dict:
                    item_dict['activeflag'] = item_dict['activeflag'] == 'Y'
                if 'settlementperiod' in item_dict:
                    item_dict['settlementperiod'] = int(
                        item_dict['settlementperiod'])

                self.post_item_cleanup(item_dict)
                self.items.append(item_dict)
        else:
            for result_set in self.MULTI_RESULTS:
                self.multi[result_set[0]] = []
                for item in xml.xpath(result_set[1]):
                    item_dict = map_xml_to_dict(item, self.XML_MAPPING)
                    if 'activeFlags' in item_dict:
                        item_dict['activeflag'] = item_dict[
                            'activeflag'] == 'Y'
                    if 'settlementperiod' in item_dict:
                        item_dict['settlementperiod'] = int(
                            item_dict['settlementperiod'])

                    self.post_item_cleanup(item_dict)
                    #                    print(item_dict)
                    self.multi[result_set[0]].append(item_dict)

        return True
コード例 #2
0
ファイル: generation_type.py プロジェクト: zathras777/pywind
    def get_data(self):
        """ Get data from the BM Reports website. Try 3 times.
        """
        resp = get_or_post_a_url(self.URL, params=self.PARAMS)
        self.xml = parse_response_as_xml(resp)
        if self.xml is None:
            return

        for section in ['INST', 'HH', 'LAST24H']:
            self.sections.append(GenerationPeriod(self.xml.xpath(section)[0]))
コード例 #3
0
    def get_data(self):
        """ Get data from the BM Reports website. Try 3 times.
        """
        resp = get_or_post_a_url(self.URL, params=self.PARAMS)
        self.xml = parse_response_as_xml(resp)
        if self.xml is None:
            return

        for section in ['INST', 'HH', 'LAST24H']:
            self.sections.append(GenerationPeriod(self.xml.xpath(section)[0]))
コード例 #4
0
ファイル: api.py プロジェクト: zathras777/pywind
    def get_data(self, **params):
        """ Get data from the Elexon servers and attempt to parse it into a series of
            dicts each representing a record. Parameters are passed as a dict.
            Multiple sets of data are created in the multi member, single sets in items.
        """
        if self.report is None:
            raise Exception("ElexonAPI objects require the report be set before use.")
        if self.apikey is None:
            raise Exception("An API key is required to use the Elexon API accessor functionality")

        url = make_elexon_url(self.report, self.version)
        params.update({'APIKey': self.apikey, 'ServiceType': 'xml'})
        req = get_or_post_a_url(url, params=params)
#        print(req.content)
        xml = parse_response_as_xml(req)
        http = xml.xpath('/response/responseMetadata/httpCode')
        response_code = int(http[0].text)
        if response_code == 204:
            print("No content returned, but no error reported.")
            return True
        elif response_code != 200:
            print("No data returned. Error reported.")
            err = xml.xpath('/response/responseMetadata/description')
            print(err[0].text)
            return False

        if self.MULTI_RESULTS is None:
            for item in xml.xpath('/response/responseBody/responseList/item'):
                item_dict = map_xml_to_dict(item, self.XML_MAPPING)

                if 'activeflag' in item_dict:
                   item_dict['activeflag'] = item_dict['activeflag'] == 'Y'
                if 'settlementperiod' in item_dict:
                    item_dict['settlementperiod'] = int(item_dict['settlementperiod'])

                self.post_item_cleanup(item_dict)
                self.items.append(item_dict)
        else:
            for result_set in self.MULTI_RESULTS:
                self.multi[result_set[0]] = []
                for item in xml.xpath(result_set[1]):
                    item_dict = map_xml_to_dict(item, self.XML_MAPPING)
                    if 'activeFlags' in item_dict:
                       item_dict['activeflag'] = item_dict['activeflag'] == 'Y'
                    if 'settlementperiod' in item_dict:
                        item_dict['settlementperiod'] = int(item_dict['settlementperiod'])

                    self.post_item_cleanup(item_dict)
#                    print(item_dict)
                    self.multi[result_set[0]].append(item_dict)

        return True
コード例 #5
0
ファイル: prices.py プロジェクト: ragnag/pywind
    def get_data(self):
        """ Get the data from the remote server. """
        data = {'element': 'SYSPRICE', 'dT': self.dtt.strftime("%Y-%m-%d")}
        resp = get_or_post_a_url(self.URL, params=data)
        self.xml = parse_response_as_xml(resp)
        if self.xml is None:
            return False

        for elm in self.xml.xpath('.//ELEMENT'):
            data = {}
            for elm2 in elm.getchildren():
                if elm2.tag == 'SP':
                    data['period'] = int(elm2.text)
                elif elm2.tag == 'SD':
                    data['date'] = datetime.strptime(elm2.text, "%Y-%m-%d")
                else:
                    data[elm2.tag.lower()] = elm2.text
            self.prices.append(data)
        return len(self.prices) > 0
コード例 #6
0
ファイル: api.py プロジェクト: arctellion/pywind
    def get_data(self, **params):
        if self.report is None:
            raise Exception("ElexonAPI objects require the report be set before use.")
        if self.apikey is None:
            raise Exception("An API key is required to use the Elexon API accessor functionality")

        url = make_elexon_url(self.report, self.version)
        params.update({'APIKey': self.apikey, 'ServiceType': 'xml'})
        req = get_or_post_a_url(url, params=params)
        xml = parse_response_as_xml(req)
        http = xml.xpath('/response/responseMetadata/httpCode')
        if int(http[0].text) != 200:
            return False

        for item in xml.xpath('/response/responseBody/responseList/item'):
            item_dict = map_children_to_dict(item, self.XML_MAPPING)
            self.post_item_cleanup(item_dict)
            self.items.append(item_dict)

        return True
コード例 #7
0
ファイル: prices.py プロジェクト: arctellion/pywind
    def get_data(self):
        """ Get the data from the remote server. """
        data = {'element': 'SYSPRICE',
                'dT': self.dtt.strftime("%Y-%m-%d")}
        resp = get_or_post_a_url(self.URL, params=data)
        self.xml = parse_response_as_xml(resp)
        if self.xml is None:
            return False

        for elm in self.xml.xpath('.//ELEMENT'):
            data = {}
            for elm2 in elm.getchildren():
                if elm2.tag == 'SP':
                    data['period'] = int(elm2.text)
                elif elm2.tag == 'SD':
                    data['date'] = datetime.strptime(elm2.text, "%Y-%m-%d")
                else:
                    data[elm2.tag.lower()] = elm2.text
            self.prices.append(data)
        return len(self.prices) > 0
コード例 #8
0
ファイル: unit.py プロジェクト: arctellion/pywind
    def _process(self, req):
        """ Process the XML returned from the request. This will contain a
            series of BMU elements, e.g.

            <BMU ID="T_WBUPS-4"
                 TYPE="T"
                 LEAD_PARTY="West Burton Limited"
                 NGC_NAME="WBUPS-4">
              <VOLUME>
                <BID_VALUES>
                  <ORIGINAL>
                    <M1>-6.0833</M1>
                    <TOTAL>-6.0833</TOTAL>
                  </ORIGINAL>
                  <TAGGED>
                    <M1>-6.0833</M1>
                    <TOTAL>-6.0833</TOTAL>
                  </TAGGED>
                  <REPRICED/>
                  <ORIGINALPRICED/>
                </BID_VALUES>
                <OFFER_VALUES>
                  <ORIGINAL/>
                  <TAGGED/>
                  <REPRICED/>
                  <ORIGINALPRICED/>
                </OFFER_VALUES>
              </VOLUME>
              <CASHFLOW>
                <BID_VALUES>
                  <M1>-203.3800</M1>
                  <TOTAL>-203.3800</TOTAL>
                </BID_VALUES>
                <OFFER_VALUES/>
              </CASHFLOW>
            </BMU>

            Each units record shows the details of Bids & Offers made
            during the settlement period. The actual accepted volumes
            should be shown in the ORIGINAL elements.
            Units can have both Bid & Offer results in the same Settlement Period.
        """
        self.xml = parse_response_as_xml(req)
        if self.xml is None:
            return False

        for bmu in self.xml.xpath(".//ACCEPT_PERIOD_TOTS//*//BMU"):
            bud = BalancingUnitData(bmu)
#            bmu.get('ID'),
#                                    bmu.get('TYPE'),
#                                    bmu.get('LEAD_PARTY'),
#                                    bmu.get('NGC_NAME'))
#            bmud = {
#                'id': bmu.get('ID'),
#                'type': bmu.get('TYPE'),
#                'lead': bmu.get('LEAD_PARTY'),
#                'ngc': bmu.get('NGC_NAME'),
#            }
#            bmud['cashflow'] = _walk_nodes(bmu.xpath('.//CASHFLOW')[0])
#            bmud['volume'] = _walk_nodes(bmu.xpath('.//VOLUME')[0])
            self.data.append(bud)
        return len(self.data) > 0
コード例 #9
0
    def _process(self, req):
        """ Process the XML returned from the request. This will contain a
            series of BMU elements, e.g.

            <BMU ID="T_WBUPS-4"
                 TYPE="T"
                 LEAD_PARTY="West Burton Limited"
                 NGC_NAME="WBUPS-4">
              <VOLUME>
                <BID_VALUES>
                  <ORIGINAL>
                    <M1>-6.0833</M1>
                    <TOTAL>-6.0833</TOTAL>
                  </ORIGINAL>
                  <TAGGED>
                    <M1>-6.0833</M1>
                    <TOTAL>-6.0833</TOTAL>
                  </TAGGED>
                  <REPRICED/>
                  <ORIGINALPRICED/>
                </BID_VALUES>
                <OFFER_VALUES>
                  <ORIGINAL/>
                  <TAGGED/>
                  <REPRICED/>
                  <ORIGINALPRICED/>
                </OFFER_VALUES>
              </VOLUME>
              <CASHFLOW>
                <BID_VALUES>
                  <M1>-203.3800</M1>
                  <TOTAL>-203.3800</TOTAL>
                </BID_VALUES>
                <OFFER_VALUES/>
              </CASHFLOW>
            </BMU>

            Each units record shows the details of Bids & Offers made
            during the settlement period. The actual accepted volumes
            should be shown in the ORIGINAL elements.
            Units can have both Bid & Offer results in the same Settlement Period.
        """
        self.xml = parse_response_as_xml(req)
        if self.xml is None:
            return False

        for bmu in self.xml.xpath(".//ACCEPT_PERIOD_TOTS//*//BMU"):
            bud = BalancingUnitData(bmu)
            #            bmu.get('ID'),
            #                                    bmu.get('TYPE'),
            #                                    bmu.get('LEAD_PARTY'),
            #                                    bmu.get('NGC_NAME'))
            #            bmud = {
            #                'id': bmu.get('ID'),
            #                'type': bmu.get('TYPE'),
            #                'lead': bmu.get('LEAD_PARTY'),
            #                'ngc': bmu.get('NGC_NAME'),
            #            }
            #            bmud['cashflow'] = _walk_nodes(bmu.xpath('.//CASHFLOW')[0])
            #            bmud['volume'] = _walk_nodes(bmu.xpath('.//VOLUME')[0])
            self.data.append(bud)
        return len(self.data) > 0