Skip to content

Commit

Permalink
Apply autopep linting
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Mehani <[email protected]>
  • Loading branch information
shtrom committed Aug 13, 2023
1 parent ea2807a commit 25aa02f
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions AuroraPlus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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]
Expand All @@ -105,4 +105,4 @@ def getcurrent(self):
else:
self.Error = 'Current request failed: ' + current.reason
except Timeout:
self.Error = 'Current request timed out'
self.Error = 'Current request timed out'

0 comments on commit 25aa02f

Please sign in to comment.