From 25aa02fd3e8cad7ccc658012619d1d75b3aacb9b Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sun, 13 Aug 2023 22:55:32 +1000 Subject: [PATCH] Apply autopep linting Signed-off-by: Olivier Mehani --- AuroraPlus/__init__.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/AuroraPlus/__init__.py b/AuroraPlus/__init__.py index 9f038d6..48c3cda 100644 --- a/AuroraPlus/__init__.py +++ b/AuroraPlus/__init__.py @@ -3,42 +3,42 @@ from requests.adapters import HTTPAdapter from requests.exceptions import Timeout + class api: def __init__(self, username, password): self.Error = None self.token = None - self.url = 'https://api.auroraenergy.com.au/api' + self.url = 'https://api.auroraenergy.com.au/api' api_adapter = HTTPAdapter(max_retries=2) - + """Create a session and perform all requests in the same session""" session = requests.Session() session.mount(self.url, api_adapter) - session.headers.update({'Accept': 'application/json', 'User-Agent': 'AuroraPlus.py', 'Accept-Encoding' : 'gzip, deflate, br', 'Connection' : 'keep-alive' }) + session.headers.update({'Accept': 'application/json', 'User-Agent': 'AuroraPlus.py', 'Accept-Encoding': 'gzip, deflate, br', 'Connection': 'keep-alive'}) self.session = session """Try to get token, retry if failed""" self.gettoken(username, password) - - def gettoken(self, username, password): + def gettoken(self, username, password): """Get access token""" try: - token = self.session.post(self.url+'/identity/login',data={'username': username, 'password': password}, timeout=(6)) + token = self.session.post(self.url + '/identity/login', data={'username': username, 'password': password}, timeout=(6)) if (token.status_code == 200): tokenjson = token.json() self.token = tokenjson['accessToken'] """Get CustomerID and ServiceAgreementID""" - current = self.session.get(self.url+'/customers/current',headers={'Authorization': self.token}).json()[0] + current = self.session.get(self.url + '/customers/current', headers={'Authorization': self.token}).json()[0] self.customerId = current['CustomerID'] """Loop through premises to get active """ premises = current['Premises'] for premise in premises: if (premise['ServiceAgreementStatus'] == 'Active'): - self.Active = premise['ServiceAgreementStatus'] + self.Active = premise['ServiceAgreementStatus'] self.serviceAgreementID = premise['ServiceAgreementID'] if (self.Active != 'Active'): self.Error = 'No active premise found' @@ -80,7 +80,7 @@ def getyear(self): def getcurrent(self): try: """Request current customer data""" - current = self.session.get(self.url+'/customers/current',headers={'Authorization': self.token}) + current = self.session.get(self.url + '/customers/current', headers={'Authorization': self.token}) if (current.status_code == 200): currentjson = current.json()[0] @@ -105,4 +105,4 @@ def getcurrent(self): else: self.Error = 'Current request failed: ' + current.reason except Timeout: - self.Error = 'Current request timed out' \ No newline at end of file + self.Error = 'Current request timed out'