summaryrefslogtreecommitdiff
path: root/app/login
diff options
context:
space:
mode:
authorDylan Bolger <dylan.bolger00@gmail.com>2023-10-15 21:35:22 -0500
committerDylan Bolger <dylan.bolger00@gmail.com>2023-10-15 21:35:22 -0500
commit7be27a3c4399e23506971fcee540176144e89da3 (patch)
tree37901e5d0ae07f5c44ee93d0c833aac38189821c /app/login
parentd8f609bf6c71e088ee0be093ea126df05d0211f5 (diff)
downloadcity-utilities-restful-wrapper-7be27a3c4399e23506971fcee540176144e89da3.tar.xz
city-utilities-restful-wrapper-7be27a3c4399e23506971fcee540176144e89da3.zip
Further organize modules, rename request energy request method, provide tentative data in response
Diffstat (limited to 'app/login')
-rw-r--r--app/login/login.py53
1 files changed, 0 insertions, 53 deletions
diff --git a/app/login/login.py b/app/login/login.py
deleted file mode 100644
index 511be44..0000000
--- a/app/login/login.py
+++ /dev/null
@@ -1,53 +0,0 @@
-import requests
-import re
-from ..constants.constants import loginPageHeaders, loginRequestJson, genericRequestHeaders, loginPageUri, loginRequestEndpoint
-
-def login():
- # Grab generated session keys from viewing the webpage
- aga, asi, ct = grabRequiredKeys()
- # Perform a login request using keys found on the page and JSON data (credentials)
- lt = performLoginRequest(aga, asi, ct)
- # Return the keys required to make endpoint calls
- return {
- "lt": lt,
- "aga": aga,
- "asi": asi,
- "ct": ct
- }
-
-
-def grabRequiredKeys():
- loginPageResponse = requests.get(loginPageUri, headers=loginPageHeaders)
- affinityMatcher = re.compile("CORS=(.+?);")
- affinityResults = affinityMatcher.search(loginPageResponse.headers['Set-Cookie'])
- appGatewayAffinity = affinityResults.group(1)
-
- aspNetSessionIdMatcher = re.compile("ASP\.NET\_SessionId=(.+?);")
- aspnetResults = aspNetSessionIdMatcher.search(loginPageResponse.headers['Set-Cookie'])
- aspNetSessionId = aspnetResults.group(1)
-
- csrfMatcher = re.compile("id=\"hdnCSRFToken\" value=\"(.+)\"")
- csrfResults = csrfMatcher.search(loginPageResponse.text)
- csrfToken = csrfResults.group(1)
- return appGatewayAffinity, aspNetSessionId, csrfToken
-
-def performLoginRequest(appGatewayAffinity, aspNetSessionId, csrfToken):
- loginRequestCookies = {
- 'ApplicationGatewayAffinityCORS': appGatewayAffinity,
- 'ApplicationGatewayAffinity': appGatewayAffinity,
- 'ASP.NET_SessionId': aspNetSessionId,
- }
-
- genericRequestHeaders['csrftoken'] = csrfToken
-
- loginResponse = requests.post(
- loginRequestEndpoint,
- cookies=loginRequestCookies,
- headers=genericRequestHeaders,
- json=loginRequestJson,
- )
-
- scpMatcher = re.compile("SCP=(.{36});")
- scpSearchResults = scpMatcher.search(loginResponse.headers['Set-Cookie'])
- loginToken = scpSearchResults.group(1)
- return loginToken