Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
- Added support for --extra_fields in the CLI
- Improved error handling (API 400 Bad Requests get raised as exceptions)
  • Loading branch information
JamieTaylor-TUOS committed May 3, 2023
1 parent 09b527e commit 31014d9
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# PV_Live
A Python implementation of the PV_Live web API. See https://www.solar.sheffield.ac.uk/pvlive/

**Latest Version: 1.0.0**
**Latest Version: 1.1.0**

**New! Updated 2023-05-02 to provide support for proxy connections.**

Expand Down
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: c6c22792ba47f0e94e3b1e4c80b8abc3
config: d41206f947f9d5f44ca302d21f611ecd
tags: 645f666f9bcd5a90fca523b33c5a78b7
4 changes: 2 additions & 2 deletions docs/build/html/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Overview: module code &mdash; PV_Live API 1.0.0 documentation</title>
<title>Overview: module code &mdash; PV_Live API 1.1.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down Expand Up @@ -32,7 +32,7 @@
PV_Live API
</a>
<div class="version">
1.0.0
1.1.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
Expand Down
18 changes: 13 additions & 5 deletions docs/build/html/_modules/pvlive_api/pvlive.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>pvlive_api.pvlive &mdash; PV_Live API 1.0.0 documentation</title>
<title>pvlive_api.pvlive &mdash; PV_Live API 1.1.0 documentation</title>
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down Expand Up @@ -32,7 +32,7 @@
PV_Live API
</a>
<div class="version">
1.0.0
1.1.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
Expand Down Expand Up @@ -89,6 +89,7 @@ <h1>Source code for pvlive_api.pvlive</h1><div class="highlight"><pre>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">List</span><span class="p">,</span> <span class="n">Union</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">,</span> <span class="n">Dict</span><span class="p">,</span> <span class="n">Optional</span>
<span class="kn">import</span> <span class="nn">inspect</span>
<span class="kn">import</span> <span class="nn">argparse</span>
<span class="kn">import</span> <span class="nn">re</span>

<span class="kn">import</span> <span class="nn">pytz</span>
<span class="kn">import</span> <span class="nn">requests</span>
Expand Down Expand Up @@ -452,7 +453,10 @@ <h1>Source code for pvlive_api.pvlive</h1><div class="highlight"><pre>
<span class="n">page</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">proxies</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">proxies</span><span class="p">)</span>
<span class="n">page</span><span class="o">.</span><span class="n">raise_for_status</span><span class="p">()</span>
<span class="n">success</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">except</span> <span class="n">requests</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">HTTPError</span><span class="p">:</span>
<span class="k">except</span> <span class="n">requests</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">HTTPError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span>
<span class="k">if</span> <span class="n">page</span><span class="o">.</span><span class="n">status_code</span> <span class="o">==</span> <span class="mi">400</span><span class="p">:</span>
<span class="n">helper</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;&lt;p&gt;(.*)&lt;/p&gt;&quot;</span><span class="p">,</span> <span class="n">page</span><span class="o">.</span><span class="n">text</span><span class="p">)</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">raise</span> <span class="n">PVLiveException</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;PV_Live API received Bad Request (400)... </span><span class="si">{</span><span class="n">helper</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">sleep</span><span class="p">(</span><span class="n">delay</span><span class="p">)</span>
<span class="n">delay</span> <span class="o">*=</span> <span class="mi">2</span>
<span class="k">continue</span>
Expand Down Expand Up @@ -509,6 +513,10 @@ <h1>Source code for pvlive_api.pvlive</h1><div class="highlight"><pre>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--entity_id&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;&lt;entity_id&gt;&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;entity_id&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store&quot;</span><span class="p">,</span>
<span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span> <span class="n">required</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Specify an entity ID, default is 0 (i.e. national).&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--extra_fields&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;&lt;field1[,field2, ...]&gt;&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;extra_fields&quot;</span><span class="p">,</span>
<span class="n">action</span><span class="o">=</span><span class="s2">&quot;store&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">str</span><span class="p">,</span> <span class="n">required</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;installedcapacity_mwp&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Specify an extra_fields (as a comma-separated list to include when &quot;</span>
<span class="s2">&quot;requesting data from the API, defaults to &#39;installedcapacity_mwp&#39;.&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--period&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;&lt;5|30&gt;&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;period&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store&quot;</span><span class="p">,</span>
<span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span> <span class="n">required</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">choices</span><span class="o">=</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">30</span><span class="p">),</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Desired temporal resolution (in minutes) for PV outturn estimates. &quot;</span>
Expand Down Expand Up @@ -566,13 +574,13 @@ <h1>Source code for pvlive_api.pvlive</h1><div class="highlight"><pre>
<span class="n">pvl</span> <span class="o">=</span> <span class="n">PVLive</span><span class="p">(</span><span class="n">proxies</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">proxies</span><span class="p">)</span>
<span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">start</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">options</span><span class="o">.</span><span class="n">end</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">pvl</span><span class="o">.</span><span class="n">latest</span><span class="p">(</span><span class="n">entity_type</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">entity_type</span><span class="p">,</span> <span class="n">entity_id</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">entity_id</span><span class="p">,</span>
<span class="n">extra_fields</span><span class="o">=</span><span class="s2">&quot;installedcapacity_mwp&quot;</span><span class="p">,</span> <span class="n">dataframe</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">extra_fields</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">extra_fields</span><span class="p">,</span> <span class="n">dataframe</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">start</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2014</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="n">tzinfo</span><span class="o">=</span><span class="n">pytz</span><span class="o">.</span><span class="n">utc</span><span class="p">)</span> <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">start</span> <span class="ow">is</span> <span class="kc">None</span> \
<span class="k">else</span> <span class="n">options</span><span class="o">.</span><span class="n">start</span>
<span class="n">end</span> <span class="o">=</span> <span class="n">pytz</span><span class="o">.</span><span class="n">utc</span><span class="o">.</span><span class="n">localize</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">utcnow</span><span class="p">())</span> <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">end</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">options</span><span class="o">.</span><span class="n">end</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">pvl</span><span class="o">.</span><span class="n">between</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">entity_type</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">entity_type</span><span class="p">,</span> <span class="n">entity_id</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">entity_id</span><span class="p">,</span>
<span class="n">extra_fields</span><span class="o">=</span><span class="s2">&quot;installedcapacity_mwp&quot;</span><span class="p">,</span> <span class="n">period</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">period</span><span class="p">,</span>
<span class="n">extra_fields</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">extra_fields</span><span class="p">,</span> <span class="n">period</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">period</span><span class="p">,</span>
<span class="n">dataframe</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">outfile</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">data</span><span class="o">.</span><span class="n">to_csv</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">outfile</span><span class="p">,</span> <span class="n">float_format</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">%.3f</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/build/html/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
VERSION: '1.0.0',
VERSION: '1.1.0',
LANGUAGE: 'en',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
4 changes: 2 additions & 2 deletions docs/build/html/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Index &mdash; PV_Live API 1.0.0 documentation</title>
<title>Index &mdash; PV_Live API 1.1.0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down Expand Up @@ -32,7 +32,7 @@
PV_Live API
</a>
<div class="version">
1.0.0
1.1.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
Expand Down
4 changes: 2 additions & 2 deletions docs/build/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Welcome to PV_Live API’s documentation! &mdash; PV_Live API 1.0.0 documentation</title>
<title>Welcome to PV_Live API’s documentation! &mdash; PV_Live API 1.1.0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down Expand Up @@ -34,7 +34,7 @@
PV_Live API
</a>
<div class="version">
1.0.0
1.1.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
Expand Down
4 changes: 2 additions & 2 deletions docs/build/html/modules.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Modules &mdash; PV_Live API 1.0.0 documentation</title>
<title>Modules &mdash; PV_Live API 1.1.0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down Expand Up @@ -34,7 +34,7 @@
PV_Live API
</a>
<div class="version">
1.0.0
1.1.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
Expand Down
2 changes: 1 addition & 1 deletion docs/build/html/objects.inv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Sphinx inventory version 2
# Project: PV_Live API
# Version: 1.0.0
# Version: 1.1.0
# The remainder of this file is compressed using zlib.
xڥ��N�0��<�!XѵC%�"!�1��Gb��V|)��k�z< ��B�-a;������V{*Щ̅\���l5�5��g��2�+H������ ���j��e��:&WV�������Į CM����>/�52y^�9V6��>g9Ԩ��q>��Tؐ�O�%e$��\kܑ�t�۠��P&_2i� �(I �/[ȷEX��|�����5�a�����<ץ�F4����ǡ���w�b�L\N��]��f�� Q��x���ϱ��R G
4 changes: 2 additions & 2 deletions docs/build/html/py-modindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Python Module Index &mdash; PV_Live API 1.0.0 documentation</title>
<title>Python Module Index &mdash; PV_Live API 1.1.0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down Expand Up @@ -35,7 +35,7 @@
PV_Live API
</a>
<div class="version">
1.0.0
1.1.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
Expand Down
4 changes: 2 additions & 2 deletions docs/build/html/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Search &mdash; PV_Live API 1.0.0 documentation</title>
<title>Search &mdash; PV_Live API 1.1.0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />

Expand Down Expand Up @@ -35,7 +35,7 @@
PV_Live API
</a>
<div class="version">
1.0.0
1.1.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="#" method="get">
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
# built documents.
#
# The short X.Y version.
version = u'1.0.0'
version = u'1.1.0'
# The full version, including alpha/beta/rc tags.
release = u'1.0.0'
release = u'1.1.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
Loading

0 comments on commit 31014d9

Please sign in to comment.