def fetch_exchange_by_bidding_zone(bidding_zone1='DK1', bidding_zone2='NO2', session=None):
bidding_zone_a, bidding_zone_b = sorted([bidding_zone1, bidding_zone2])
r = session or requests.session()
timestamp = arrow.now().timestamp * 1000
url = 'http://driftsdata.statnett.no/restapi/PhysicalFlowMap/GetFlow?Ticks=%d' % timestamp
response = r.get(url)
obj = response.json()
exchange = filter(
lambda x: set([x['OutAreaElspotId'], x['InAreaElspotId']]) == set([bidding_zone_a, bidding_zone_b]),
obj)[0]
return {
'sortedBiddingZones': '->'.join([bidding_zone_a, bidding_zone_b]),
'netFlow': exchange['Value'] if bidding_zone_a == exchange['OutAreaElspotId'] else -1 * exchange['Value'],
'datetime': arrow.get(obj[0]['MeasureDate'] / 1000).datetime,
'source': 'driftsdata.stattnet.no',
}
评论列表
文章目录