Skip to content

Commit

Permalink
Returned IDK is not JSON compliant. Moving to YAML, which is less str…
Browse files Browse the repository at this point in the history
…ict.

Solves #6.

Signed-off-by: Trocotronic <[email protected]>
  • Loading branch information
trocotronic committed Jul 19, 2023
1 parent ed4139f commit ae5d9e9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions NativeAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import credentials
from vsr import VSR
import yaml

logging.basicConfig(format='[%(asctime)s] [%(name)s::%(levelname)s] %(message)s', datefmt='%d/%m/%Y %H:%M:%S')

Expand Down Expand Up @@ -169,7 +170,7 @@ def __command(self, command, post=None, data=None, dashboard=None, accept='appli
if (secure_token):
headers['X-MBBSecToken'] = secure_token
r = self.__get_url(dashboard+command, json=post, post=data, headers=headers)
if ('json' in r.headers['Content-Type']):
if ('json' in r.headers.get('Content-Type', [])):
jr = r.json()
return jr
return r
Expand Down Expand Up @@ -264,10 +265,12 @@ def __get_idk(self, soup):
scripts = soup.find_all('script')
for script in scripts:
if script.string and 'window._IDK' in script.string:
print(script.string)
try:
idk_txt = '{'+re.search(r'\{(.*)\}',script.string,re.M|re.S).group(1)+'}'
idk_txt = re.sub(r'([\{\s,])(\w+)(:)', r'\1"\2"\3', idk_txt.replace('\'','"'))
idk = json.loads(idk_txt)
print(idk_txt)
idk = yaml.load(idk_txt, Loader=yaml.FullLoader)
return idk
except json.decoder.JSONDecodeError:
raise VWError('Cannot find IDK credentials')
Expand Down

0 comments on commit ae5d9e9

Please sign in to comment.