california-midasapi 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- california_midasapi-0.0.2/.github/workflows/python-publish.yml +48 -0
- california_midasapi-0.0.2/.gitignore +165 -0
- california_midasapi-0.0.2/LICENSE.md +11 -0
- california_midasapi-0.0.2/PKG-INFO +66 -0
- california_midasapi-0.0.2/README.md +48 -0
- california_midasapi-0.0.2/california_midasapi.egg-info/PKG-INFO +66 -0
- california_midasapi-0.0.2/california_midasapi.egg-info/SOURCES.txt +16 -0
- california_midasapi-0.0.2/california_midasapi.egg-info/dependency_links.txt +1 -0
- california_midasapi-0.0.2/california_midasapi.egg-info/requires.txt +3 -0
- california_midasapi-0.0.2/california_midasapi.egg-info/top_level.txt +1 -0
- california_midasapi-0.0.2/midas/Midas.py +9 -0
- california_midasapi-0.0.2/midas/__init__.py +1 -0
- california_midasapi-0.0.2/midas/authentication.py +49 -0
- california_midasapi-0.0.2/midas/internal.py +41 -0
- california_midasapi-0.0.2/midas/ratelist.py +46 -0
- california_midasapi-0.0.2/midas/types.py +55 -0
- california_midasapi-0.0.2/pyproject.toml +28 -0
- california_midasapi-0.0.2/setup.cfg +4 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# This workflow will upload a Python Package using Twine when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
|
|
3
|
+
|
|
4
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
5
|
+
# They are provided by a third-party and are governed by
|
|
6
|
+
# separate terms of service, privacy policy, and support
|
|
7
|
+
# documentation.
|
|
8
|
+
|
|
9
|
+
name: Upload Python Package
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
push:
|
|
13
|
+
branches: [ "main" ]
|
|
14
|
+
# Publish semver tags as releases.
|
|
15
|
+
tags: [ 'v*.*.*' ]
|
|
16
|
+
|
|
17
|
+
permissions:
|
|
18
|
+
contents: read
|
|
19
|
+
|
|
20
|
+
jobs:
|
|
21
|
+
deploy:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
environment: release
|
|
24
|
+
permissions:
|
|
25
|
+
id-token: write
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v4
|
|
29
|
+
- name: Set up Python
|
|
30
|
+
uses: actions/setup-python@v3
|
|
31
|
+
with:
|
|
32
|
+
python-version: '3.x'
|
|
33
|
+
- name: Install dependencies
|
|
34
|
+
run: |
|
|
35
|
+
python -m pip install --upgrade pip
|
|
36
|
+
pip install build
|
|
37
|
+
- name: Build package
|
|
38
|
+
run: python -m build
|
|
39
|
+
- name: Publish package
|
|
40
|
+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
|
41
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
42
|
+
- name: Publish package to TestPyPI
|
|
43
|
+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
|
44
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
45
|
+
with:
|
|
46
|
+
user: __token__
|
|
47
|
+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
|
|
48
|
+
repository_url: https://test.pypi.org/legacy/
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
110
|
+
.pdm.toml
|
|
111
|
+
.pdm-python
|
|
112
|
+
.pdm-build/
|
|
113
|
+
|
|
114
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
115
|
+
__pypackages__/
|
|
116
|
+
|
|
117
|
+
# Celery stuff
|
|
118
|
+
celerybeat-schedule
|
|
119
|
+
celerybeat.pid
|
|
120
|
+
|
|
121
|
+
# SageMath parsed files
|
|
122
|
+
*.sage.py
|
|
123
|
+
|
|
124
|
+
# Environments
|
|
125
|
+
.env
|
|
126
|
+
.venv
|
|
127
|
+
env/
|
|
128
|
+
venv/
|
|
129
|
+
ENV/
|
|
130
|
+
env.bak/
|
|
131
|
+
venv.bak/
|
|
132
|
+
|
|
133
|
+
# Spyder project settings
|
|
134
|
+
.spyderproject
|
|
135
|
+
.spyproject
|
|
136
|
+
|
|
137
|
+
# Rope project settings
|
|
138
|
+
.ropeproject
|
|
139
|
+
|
|
140
|
+
# mkdocs documentation
|
|
141
|
+
/site
|
|
142
|
+
|
|
143
|
+
# mypy
|
|
144
|
+
.mypy_cache/
|
|
145
|
+
.dmypy.json
|
|
146
|
+
dmypy.json
|
|
147
|
+
|
|
148
|
+
# Pyre type checker
|
|
149
|
+
.pyre/
|
|
150
|
+
|
|
151
|
+
# pytype static type analyzer
|
|
152
|
+
.pytype/
|
|
153
|
+
|
|
154
|
+
# Cython debug symbols
|
|
155
|
+
cython_debug/
|
|
156
|
+
|
|
157
|
+
# PyCharm
|
|
158
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
159
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
160
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
161
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
162
|
+
#.idea/
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
__test.py
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2024 MattDahEpic
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: california-midasapi
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Python wrapper for California's energy price API MIDAS.
|
|
5
|
+
Author-email: MattDahEpic <matt+california-midasapipypi@mattdahepic.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: california,api,energy,midas,price
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Topic :: Scientific/Engineering
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE.md
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Requires-Dist: PyJWT
|
|
17
|
+
Requires-Dist: python-dateutil
|
|
18
|
+
|
|
19
|
+
# california-midasapi
|
|
20
|
+
A Python wrapper for the California Energy Comission (CEC)'s Market Informed Demand Automation Server (MIDAS) energy price API.
|
|
21
|
+
This API lets you get info about energy prices in California from utilities regulated by the CEC, which is all the big ones (PG&E, SCE, SDG&E, SMUD, etc.) and some smaller municipal utilities. If you have a Rate Identification Number (RIN) QA Code on your electric bill you can use this API to get your electricity price in real time.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
1. Start by registering an account with MIDAS. There is no webpage for this so I have provided a helper. You only have to register an account once.
|
|
26
|
+
```python
|
|
27
|
+
from midas.authentication import Midas as Auth
|
|
28
|
+
response = Auth.register("username", "password", "email@email.email", "Full Name")
|
|
29
|
+
print(response)
|
|
30
|
+
```
|
|
31
|
+
You should see `User account for username was successfully created. A verification email has been sent to email@email.email. Please click the link in the email in order to start using the API.`.
|
|
32
|
+
Click the link in the email, then you can use the rest of the API as described below.
|
|
33
|
+
|
|
34
|
+
2. Create a `Midas` object:
|
|
35
|
+
```python
|
|
36
|
+
from midas import Midas
|
|
37
|
+
midas = Midas("username", "password")
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
3. Access the API methods using this object:
|
|
41
|
+
```python
|
|
42
|
+
# Get basic info about all rates
|
|
43
|
+
from midas.ratelist import RINFilter
|
|
44
|
+
rates = midas.GetAvailableRates(RINFilter.TARIFF)
|
|
45
|
+
print(rates) # ~40k+ items at writing
|
|
46
|
+
|
|
47
|
+
# Get specific info about one rate
|
|
48
|
+
ratedata = midas.GetRateInfo('USCA-SMSM-AD00-0000')
|
|
49
|
+
print(ratedata)
|
|
50
|
+
# Get the currently applicable value from a rate (local filtering)
|
|
51
|
+
print(ratedata.GetCurrentTariffs())
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## Contributing
|
|
56
|
+
Contributions are welcome, please submit a PR!
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## More Information & Thanks
|
|
60
|
+
More info about MIDAS can be found at https://midasapi.energy.ca.gov/
|
|
61
|
+
Thank you to the CEC for providing example code at https://github.com/morganmshep/MIDAS-Python-Repository
|
|
62
|
+
|
|
63
|
+
## Projects using this library
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
If you have a project using this library, we'd love to hear about it! Let us know and we'll add it to this list.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# california-midasapi
|
|
2
|
+
A Python wrapper for the California Energy Comission (CEC)'s Market Informed Demand Automation Server (MIDAS) energy price API.
|
|
3
|
+
This API lets you get info about energy prices in California from utilities regulated by the CEC, which is all the big ones (PG&E, SCE, SDG&E, SMUD, etc.) and some smaller municipal utilities. If you have a Rate Identification Number (RIN) QA Code on your electric bill you can use this API to get your electricity price in real time.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
1. Start by registering an account with MIDAS. There is no webpage for this so I have provided a helper. You only have to register an account once.
|
|
8
|
+
```python
|
|
9
|
+
from midas.authentication import Midas as Auth
|
|
10
|
+
response = Auth.register("username", "password", "email@email.email", "Full Name")
|
|
11
|
+
print(response)
|
|
12
|
+
```
|
|
13
|
+
You should see `User account for username was successfully created. A verification email has been sent to email@email.email. Please click the link in the email in order to start using the API.`.
|
|
14
|
+
Click the link in the email, then you can use the rest of the API as described below.
|
|
15
|
+
|
|
16
|
+
2. Create a `Midas` object:
|
|
17
|
+
```python
|
|
18
|
+
from midas import Midas
|
|
19
|
+
midas = Midas("username", "password")
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
3. Access the API methods using this object:
|
|
23
|
+
```python
|
|
24
|
+
# Get basic info about all rates
|
|
25
|
+
from midas.ratelist import RINFilter
|
|
26
|
+
rates = midas.GetAvailableRates(RINFilter.TARIFF)
|
|
27
|
+
print(rates) # ~40k+ items at writing
|
|
28
|
+
|
|
29
|
+
# Get specific info about one rate
|
|
30
|
+
ratedata = midas.GetRateInfo('USCA-SMSM-AD00-0000')
|
|
31
|
+
print(ratedata)
|
|
32
|
+
# Get the currently applicable value from a rate (local filtering)
|
|
33
|
+
print(ratedata.GetCurrentTariffs())
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Contributing
|
|
38
|
+
Contributions are welcome, please submit a PR!
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## More Information & Thanks
|
|
42
|
+
More info about MIDAS can be found at https://midasapi.energy.ca.gov/
|
|
43
|
+
Thank you to the CEC for providing example code at https://github.com/morganmshep/MIDAS-Python-Repository
|
|
44
|
+
|
|
45
|
+
## Projects using this library
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
If you have a project using this library, we'd love to hear about it! Let us know and we'll add it to this list.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: california-midasapi
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Python wrapper for California's energy price API MIDAS.
|
|
5
|
+
Author-email: MattDahEpic <matt+california-midasapipypi@mattdahepic.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: california,api,energy,midas,price
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Topic :: Scientific/Engineering
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE.md
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Requires-Dist: PyJWT
|
|
17
|
+
Requires-Dist: python-dateutil
|
|
18
|
+
|
|
19
|
+
# california-midasapi
|
|
20
|
+
A Python wrapper for the California Energy Comission (CEC)'s Market Informed Demand Automation Server (MIDAS) energy price API.
|
|
21
|
+
This API lets you get info about energy prices in California from utilities regulated by the CEC, which is all the big ones (PG&E, SCE, SDG&E, SMUD, etc.) and some smaller municipal utilities. If you have a Rate Identification Number (RIN) QA Code on your electric bill you can use this API to get your electricity price in real time.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
1. Start by registering an account with MIDAS. There is no webpage for this so I have provided a helper. You only have to register an account once.
|
|
26
|
+
```python
|
|
27
|
+
from midas.authentication import Midas as Auth
|
|
28
|
+
response = Auth.register("username", "password", "email@email.email", "Full Name")
|
|
29
|
+
print(response)
|
|
30
|
+
```
|
|
31
|
+
You should see `User account for username was successfully created. A verification email has been sent to email@email.email. Please click the link in the email in order to start using the API.`.
|
|
32
|
+
Click the link in the email, then you can use the rest of the API as described below.
|
|
33
|
+
|
|
34
|
+
2. Create a `Midas` object:
|
|
35
|
+
```python
|
|
36
|
+
from midas import Midas
|
|
37
|
+
midas = Midas("username", "password")
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
3. Access the API methods using this object:
|
|
41
|
+
```python
|
|
42
|
+
# Get basic info about all rates
|
|
43
|
+
from midas.ratelist import RINFilter
|
|
44
|
+
rates = midas.GetAvailableRates(RINFilter.TARIFF)
|
|
45
|
+
print(rates) # ~40k+ items at writing
|
|
46
|
+
|
|
47
|
+
# Get specific info about one rate
|
|
48
|
+
ratedata = midas.GetRateInfo('USCA-SMSM-AD00-0000')
|
|
49
|
+
print(ratedata)
|
|
50
|
+
# Get the currently applicable value from a rate (local filtering)
|
|
51
|
+
print(ratedata.GetCurrentTariffs())
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## Contributing
|
|
56
|
+
Contributions are welcome, please submit a PR!
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## More Information & Thanks
|
|
60
|
+
More info about MIDAS can be found at https://midasapi.energy.ca.gov/
|
|
61
|
+
Thank you to the CEC for providing example code at https://github.com/morganmshep/MIDAS-Python-Repository
|
|
62
|
+
|
|
63
|
+
## Projects using this library
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
If you have a project using this library, we'd love to hear about it! Let us know and we'll add it to this list.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.gitignore
|
|
2
|
+
LICENSE.md
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
.github/workflows/python-publish.yml
|
|
6
|
+
california_midasapi.egg-info/PKG-INFO
|
|
7
|
+
california_midasapi.egg-info/SOURCES.txt
|
|
8
|
+
california_midasapi.egg-info/dependency_links.txt
|
|
9
|
+
california_midasapi.egg-info/requires.txt
|
|
10
|
+
california_midasapi.egg-info/top_level.txt
|
|
11
|
+
midas/Midas.py
|
|
12
|
+
midas/__init__.py
|
|
13
|
+
midas/authentication.py
|
|
14
|
+
midas/internal.py
|
|
15
|
+
midas/ratelist.py
|
|
16
|
+
midas/types.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
midas
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from midas.authentication import Midas as MidasAuth
|
|
2
|
+
from midas.ratelist import Midas as MidasRateList
|
|
3
|
+
|
|
4
|
+
class Midas(MidasAuth, MidasRateList):
|
|
5
|
+
"""
|
|
6
|
+
Python API for California's energy price database MIDAS.
|
|
7
|
+
|
|
8
|
+
Main class, imports most things from modules.
|
|
9
|
+
"""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from midas.Midas import Midas, MidasAuth, MidasRateList
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import json
|
|
3
|
+
import base64
|
|
4
|
+
from midas.internal import Midas as Internal
|
|
5
|
+
|
|
6
|
+
class Midas(Internal):
|
|
7
|
+
def __init__(self, username: str, password: str):
|
|
8
|
+
"""
|
|
9
|
+
Create a new API wrapper instance using the given credentials.
|
|
10
|
+
|
|
11
|
+
Credentials are required, if you don't have an account use the static `register` method
|
|
12
|
+
"""
|
|
13
|
+
self.username = username
|
|
14
|
+
self.password = password
|
|
15
|
+
self.auth_token: str = None
|
|
16
|
+
|
|
17
|
+
@staticmethod
|
|
18
|
+
def register(username: str, password: str, email: str, fullname: str, organization: str = None) -> str:
|
|
19
|
+
"""
|
|
20
|
+
Create a new account with the MIDAS server.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
username64 = str(base64.b64encode(username.encode("utf-8")), "utf-8")
|
|
25
|
+
password64 = str(base64.b64encode(password.encode("utf-8")), "utf-8")
|
|
26
|
+
email64 = str(base64.b64encode(email.encode("utf-8")), "utf-8")
|
|
27
|
+
fullname64 = str(base64.b64encode(fullname.encode("utf-8")), "utf-8")
|
|
28
|
+
|
|
29
|
+
registration_info = {
|
|
30
|
+
"username":username64,
|
|
31
|
+
"password":password64,
|
|
32
|
+
"emailaddress":email64,
|
|
33
|
+
"fullname":fullname64
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (organization is not None):
|
|
37
|
+
organization64 = str(base64.b64encode(organization.encode("utf-8")), "utf-8")
|
|
38
|
+
registration_info["organization"] = organization64
|
|
39
|
+
|
|
40
|
+
url = 'https://midasapi.energy.ca.gov/api/registration'
|
|
41
|
+
headers = {"Content-Type":"application/json"}
|
|
42
|
+
|
|
43
|
+
response = requests.post(url, data=json.dumps(registration_info), headers=headers)
|
|
44
|
+
|
|
45
|
+
#Prints below will return 200 response for successful call
|
|
46
|
+
print(response)
|
|
47
|
+
#Response text should be: 'User account for your_user_name was successfully created. A verification email has been sent to your_email. Please click the link in the email in order to start using the API.'
|
|
48
|
+
print(response.text)
|
|
49
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
import requests
|
|
3
|
+
import base64
|
|
4
|
+
import jwt
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
class Midas():
|
|
8
|
+
def __request(self, method: Literal['GET', 'POST'], url: str):
|
|
9
|
+
"""Preform a request with the stored auth token and return the body."""
|
|
10
|
+
if (self.auth_token is None or not Midas.__isTokenValid(self.auth_token)):
|
|
11
|
+
self.__loginAndStore(self.username, self.password)
|
|
12
|
+
headers = {
|
|
13
|
+
'Accept': 'application/json',
|
|
14
|
+
'User-Agent': 'california-midasapi.py',
|
|
15
|
+
'Authorization': "Bearer " + self.auth_token,
|
|
16
|
+
}
|
|
17
|
+
response = requests.request(method, url, headers=headers)
|
|
18
|
+
if (not response.ok):
|
|
19
|
+
raise f"Error preforming request: {response.status_code} {response.text}"
|
|
20
|
+
return response.text
|
|
21
|
+
|
|
22
|
+
def __loginAndStore(self, username: str, password: str):
|
|
23
|
+
'''
|
|
24
|
+
Logs in with a username and password, storing the JWT token for use in future calls.
|
|
25
|
+
'''
|
|
26
|
+
credentials = username + ":" + password
|
|
27
|
+
credentials_encodedBytes = base64.b64encode(credentials.encode("utf-8"))
|
|
28
|
+
|
|
29
|
+
headers = {b'Authorization': b'BASIC ' + credentials_encodedBytes}
|
|
30
|
+
url = 'https://midasapi.energy.ca.gov/api/token'
|
|
31
|
+
|
|
32
|
+
response = requests.get(url,headers=headers)
|
|
33
|
+
|
|
34
|
+
self.auth_token = response.headers['Token']
|
|
35
|
+
|
|
36
|
+
@staticmethod
|
|
37
|
+
def __isTokenValid(token: str) -> bool:
|
|
38
|
+
"""Return if the provided token is still valid"""
|
|
39
|
+
decoded = jwt.decode(token, algorithms=["HS256"], options={"verify_signature": False})
|
|
40
|
+
future = time.time() + 120 # 2 minutes from now
|
|
41
|
+
return decoded["exp"] > future # expires more than set time from now
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from midas.internal import Midas as Internal
|
|
2
|
+
from midas.types import RateListItem, ValueInfoItem, RateInfo
|
|
3
|
+
from typing import Literal
|
|
4
|
+
from enum import Enum
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
class RINFilter(Enum):
|
|
8
|
+
"""Filter options for the RIN list."""
|
|
9
|
+
ALL = 0
|
|
10
|
+
TARIFF = 1
|
|
11
|
+
GHG_EMISSION = 2
|
|
12
|
+
FLEX_ALERT = 3
|
|
13
|
+
|
|
14
|
+
class Midas(Internal):
|
|
15
|
+
|
|
16
|
+
def GetAvailableRates(self, signaltype: RINFilter) -> 'list[RateListItem]':
|
|
17
|
+
"""
|
|
18
|
+
Get all the available rates.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __rateListItemHook(dict):
|
|
22
|
+
return RateListItem(**dict)
|
|
23
|
+
|
|
24
|
+
url = 'https://midasapi.energy.ca.gov/api/valuedata?signaltype=' + str(signaltype.value)
|
|
25
|
+
response = self.__request('GET', url)
|
|
26
|
+
return (json.loads(response, object_hook=__rateListItemHook))
|
|
27
|
+
|
|
28
|
+
def GetRateInfo(self, rateID: str, queryType: Literal['alldata', 'realtime'] = 'alldata') -> RateInfo:
|
|
29
|
+
"""
|
|
30
|
+
Returns data about a given a rate.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __rateInfoObjectHook(dict):
|
|
34
|
+
# this has to handle both the parent object and its children
|
|
35
|
+
if "DateStart" in dict:
|
|
36
|
+
return ValueInfoItem(**dict)
|
|
37
|
+
elif "RateID" in dict:
|
|
38
|
+
return RateInfo(**dict)
|
|
39
|
+
else:
|
|
40
|
+
raise "Invalid object type for __rateInfoObjectHook"
|
|
41
|
+
|
|
42
|
+
# TODO what does queryType=realtime even do? all properties are None
|
|
43
|
+
url = 'https://midasapi.energy.ca.gov/api/valuedata?id=' + rateID + '&querytype=' + queryType
|
|
44
|
+
pricing_response = self.__request('GET', url)
|
|
45
|
+
|
|
46
|
+
return (json.loads(pricing_response, object_hook=__rateInfoObjectHook))
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from dateutil import parser
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class RateListItem():
|
|
8
|
+
RateID: str
|
|
9
|
+
SignalType: str
|
|
10
|
+
Description: str
|
|
11
|
+
LastUpdated: Optional[str] = None
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class ValueInfoItem:
|
|
15
|
+
ValueName: str
|
|
16
|
+
DateStart: str
|
|
17
|
+
DateEnd: str
|
|
18
|
+
DayStart: str
|
|
19
|
+
DayEnd: str
|
|
20
|
+
TimeStart: str
|
|
21
|
+
TimeEnd: str
|
|
22
|
+
value: float
|
|
23
|
+
Unit: str
|
|
24
|
+
|
|
25
|
+
def GetStart(self) -> datetime:
|
|
26
|
+
"""Get the start of this tariff as a python datetime"""
|
|
27
|
+
return parser.parse(f"{self.DateStart} {self.TimeStart} -07:00")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def GetEnd(self) -> datetime:
|
|
31
|
+
"""Get the end of this tariff as a python datetime"""
|
|
32
|
+
return parser.parse(f"{self.DateEnd} {self.TimeEnd} -07:00")
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class RateInfo:
|
|
36
|
+
RateID: str
|
|
37
|
+
SystemTime_UTC: str
|
|
38
|
+
RateName: str
|
|
39
|
+
RateType: str
|
|
40
|
+
Sector: str
|
|
41
|
+
API_Url: str
|
|
42
|
+
RatePlan_Url: str
|
|
43
|
+
EndUse: str
|
|
44
|
+
AltRateName1: str
|
|
45
|
+
AltRateName2: str
|
|
46
|
+
SignupCloseDate: str
|
|
47
|
+
ValueInformation: list[ValueInfoItem] = field(default_factory=list)
|
|
48
|
+
"""The list of tariffs"""
|
|
49
|
+
|
|
50
|
+
def GetCurrentTariffs(self) -> list[ValueInfoItem]:
|
|
51
|
+
"""Gets all tariffs that are currently active"""
|
|
52
|
+
|
|
53
|
+
# ValueInformation where getstart < now < getend
|
|
54
|
+
now = datetime.now().timestamp()
|
|
55
|
+
return list(filter(lambda t: t.GetStart().timestamp() < now and t.GetEnd().timestamp() > now, self.ValueInformation))
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "setuptools_scm"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "california-midasapi"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Python wrapper for California's energy price API MIDAS."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "MattDahEpic", email = "matt+california-midasapipypi@mattdahepic.com" },
|
|
12
|
+
]
|
|
13
|
+
license = {text = "MIT"}
|
|
14
|
+
keywords = ["california", "api", "energy", "midas", "price"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
'Development Status :: 3 - Alpha',
|
|
17
|
+
'Intended Audience :: Developers',
|
|
18
|
+
'Topic :: Scientific/Engineering',
|
|
19
|
+
'License :: OSI Approved :: MIT License',
|
|
20
|
+
'Programming Language :: Python :: 3',
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"requests",
|
|
24
|
+
"PyJWT",
|
|
25
|
+
"python-dateutil",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools_scm]
|