Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

34 allow for switching base url #38

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Tests/test_pvlive_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ def setUp(self):
"""
Setup the instance of class.
"""
self.api = PVLive()
self.api = PVLive(
retries=3,
proxies=None,
ssl_verify=True,
# domain_url="api0.solar.sheffield.ac.uk",
domain_url="api.solar.sheffield.ac.uk",
# domain_url="api.pvlive.uk"
)
self.expected_dtypes = {
"pes_id": ptypes.is_integer_dtype,
"gsp_id": ptypes.is_integer_dtype,
Expand Down
23 changes: 21 additions & 2 deletions pvlive_api/pvlive.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,27 @@ class PVLive:
Optionally specify a Dict of proxies for http and https requests in the format:
{"http": "<address>", "https": "<address>"}
"""
def __init__(self, retries: int = 3, proxies: Optional[Dict] = None, ssl_verify: bool = True):
self.domain_url = "https://api.solar.sheffield.ac.uk"
def __init__(
self,
retries: int = 3,
proxies: Optional[Dict] = None,
ssl_verify: bool = True,
domain_url: Literal[
"api0.solar.sheffield.ac.uk",
"api.solar.sheffield.ac.uk",
"api.pvlive.uk"
] = "api.solar.sheffield.ac.uk"
):
valid_domain_urls = [
"api0.solar.sheffield.ac.uk",
"api.solar.sheffield.ac.uk",
"api.pvlive.uk"
]
if domain_url not in valid_domain_urls:
raise ValueError(
f"`domain_url` of '{domain_url}' is invalid, must be one of: {valid_domain_urls}"
)
self.domain_url = f"https://{domain_url}"
self.base_url = f"{self.domain_url}/pvlive/api/v4"
self.max_range = {"national": timedelta(days=365), "regional": timedelta(days=30)}
self.retries = retries
Expand Down
Loading