-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
196 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,65 @@ | ||
On its way | ||
<h1 align="center">Welcome to Barry Energy API Client 👋</h1> | ||
<p> | ||
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" /> | ||
<a href="LICENSE" target="_blank"> | ||
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" /> | ||
</a> | ||
</p> | ||
|
||
> Simple python package to work with the API of Barry Energy. | ||
> The API documentation can be found [here](https://developer.barry.energy). | ||
> Please be aware that this project is <u>NOT</u> offical. | ||
## Install | ||
|
||
```sh | ||
pip3 install barry-energy-api | ||
``` | ||
|
||
## Usage | ||
|
||
#### Get your API Token | ||
```sh | ||
Get from mobile app under "Add-ons" -> "Barry API" | ||
``` | ||
<br> | ||
|
||
1. Import the package | ||
```python | ||
from barry_energy_api import PriceZone, BarryEnergyAPI | ||
``` | ||
2. Initialize the API | ||
```python | ||
api = BarryEnergyAPI('api-token', 5, PriceZone.DK_EAST) | ||
``` | ||
3. Get aggregated consumption for the last 5 days as defined when API was initialized. | ||
```python | ||
api.consumption() | ||
``` | ||
4. Get prices from the last two days. | ||
##### Notice that methode has overloading | ||
```python | ||
api.spotprices(2) | ||
``` | ||
|
||
|
||
## Author | ||
|
||
👤 **Emil Elkjær Nielsen** | ||
|
||
* Website: https://evsn.dk | ||
* Github: [@eelkjaer](https://github.com/eelkjaer) | ||
* LinkedIn: [@emil-elkjær](https://linkedin.com/in/emil-elkjær) | ||
|
||
## Show your support | ||
|
||
Give a ⭐️ if this project helped you! | ||
|
||
## 📝 License | ||
|
||
Copyright © 2021 [Emil Elkjær Nielsen](https://github.com/eelkjaer) <br /> | ||
This project is [MIT](LICENSE) licensed. | ||
|
||
*** | ||
_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import enum | ||
|
||
from barry_energy_api.entities import meteringpoints, spotprice, consumption | ||
from barry_energy_api.entities.consumption import getConsumption | ||
from barry_energy_api.entities.meteringpoints import getMeteringPoints | ||
from barry_energy_api.entities.spotprice import getSpotprice | ||
from barry_energy_api.utils import dateFormat, createHeader | ||
from datetime import datetime, timedelta | ||
|
||
|
||
class BarryException(Exception): | ||
pass | ||
|
||
class PriceZone(enum.Enum): | ||
""" | ||
DK_WEST = West Denmark (zip-code below 4999) | ||
DK_EAST = East Denmark (zip-code above 5000) | ||
FRANCE = Self explanatory | ||
""" | ||
DK_WEST = "DK_NORDPOOL_SPOT_DK1" | ||
DK_EAST = "DK_NORDPOOL_SPOT_DK2" | ||
FRANCE = "FR_EPEX_SPOT_FR" | ||
|
||
|
||
class BarryEnergyAPI: | ||
def __init__(self, api_token: str, pastdays: int, pricezone: PriceZone): | ||
# Sets the API key | ||
self.api_token = api_token | ||
self.pricezone = pricezone.value | ||
|
||
# Set the date range | ||
self.todate = datetime.utcnow() | ||
self.fromdate = dateFormat(self.todate - timedelta(days=pastdays)) | ||
self.todate = dateFormat(self.todate) | ||
|
||
# Creates HTTP header | ||
self.header = createHeader(self.api_token, self.fromdate, self.todate, self.pricezone) | ||
|
||
def set_startdate(self, pastdays: int): | ||
""" | ||
Changes the date which measuring is happening from. | ||
:param pastdays: | ||
Days before today | ||
""" | ||
self.fromdate = dateFormat(datetime.utcnow() - timedelta(days=pastdays)) | ||
|
||
def spotprices(self, pastdays=None): | ||
""" | ||
Gives the spot prices in the specified from/to range. | ||
Spot prices are delivered ahead of our current time, up to 24 hours ahead. | ||
The price is excluding VAT and tarrifs. | ||
""" | ||
try: | ||
headers = self.header | ||
if pastdays is not None: | ||
headers[1] = dateFormat(datetime.utcnow() - timedelta(days=pastdays)) | ||
return getSpotprice(headers) | ||
except Exception as ex: | ||
raise BarryException(str(ex)) | ||
|
||
def consumption(self, pastdays=None): | ||
""" | ||
Gives the consumption on an hourly resolution. | ||
It accepts a past from and to date and MPID/PDL as input. | ||
Note that it will not return any data unless one is a Barry customer. | ||
The data usually has two to three days of delay, which is a limitation of the regulatory authorities. | ||
""" | ||
try: | ||
headers = self.header | ||
if pastdays is not None: | ||
headers[1] = dateFormat(datetime.utcnow() - timedelta(days=pastdays)) | ||
return getConsumption(headers) | ||
except Exception as ex: | ||
raise BarryException(str(ex)) | ||
|
||
def meteringpoints(self, pastdays=None): | ||
""" | ||
Gives information on all of your metering points subscribed to Barry. | ||
This method contains metadata on your metering points, including the price area and the MPID/PDL (Metering Point Identification). | ||
""" | ||
try: | ||
headers = self.header | ||
if pastdays is not None: | ||
headers[1] = dateFormat(datetime.utcnow() - timedelta(days=pastdays)) | ||
return getMeteringPoints(headers) | ||
except Exception as ex: | ||
raise BarryException(str(ex)) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def createHeader(apitoken, fromdate, todate, pricezone): | ||
apiHeader = { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + apitoken | ||
} | ||
|
||
return [apiHeader, fromdate, todate, pricezone] | ||
|
||
|
||
def dateFormat(date): | ||
return date.strftime("%Y-%m-%dT%H:%M:%SZ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
from setuptools import setup | ||
|
||
# Thanks Frankkkkk for inspiring. | ||
def read(fname): | ||
return open(os.path.join(os.path.dirname(__file__), fname)).read() | ||
|
||
setup( | ||
name = "barry-energy-api", | ||
version = "1.0.0", | ||
author = "Emil Elkjær Nielsen", | ||
author_email = "emil@evsn.dk", | ||
description = ("Connecting to and getting data from Barry Energy's API (http://barry.energy)"), | ||
license = "LICENS", | ||
keywords = "python barry energy api electricity prices barry.energy", | ||
url = "https://github.com/eelkjaer/BarryAPIClient", | ||
packages=['barry_energy_api'], | ||
long_description=open("README.md", "r").read(), | ||
long_description_content_type="text/markdown", | ||
install_requires=[], | ||
classifiers=[ | ||
"Development Status :: 4 - Beta", | ||
"Programming Language :: Python :: 3.9", | ||
"Topic :: Utilities", | ||
"License :: OSI Approved :: MIT License", | ||
], | ||
) |