diff options
author | 2021-07-07 17:49:02 +0530 | |
---|---|---|
committer | 2021-07-07 17:49:02 +0530 | |
commit | 3a0d5aa439389a42d1fc0cdcefdae2fe597c3e56 (patch) | |
tree | 1c43d8882a7af32f57032807fa8af4a669e51199 /sdv/docker/sdvstate | |
parent | e8089a068a582ac2ceb38f9c992a2e7cc1278371 (diff) |
This patch will allow user to pass PDF file as an URL or a file path
Signed-off-by: Adarsh Yadav<adiyadav0509@gmail.com>
Change-Id: I01a211e6a44ab57aaf8e9e4d21eca2e91791646d
Diffstat (limited to 'sdv/docker/sdvstate')
-rw-r--r-- | sdv/docker/sdvstate/core/load_pdf.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/sdv/docker/sdvstate/core/load_pdf.py b/sdv/docker/sdvstate/core/load_pdf.py index 6ce22f0..fa2bf7e 100644 --- a/sdv/docker/sdvstate/core/load_pdf.py +++ b/sdv/docker/sdvstate/core/load_pdf.py @@ -18,6 +18,8 @@ import json import yaml +import requests +import os from tools.conf import settings @@ -25,9 +27,21 @@ def load_pdf(): """ Updates settings with PDF data """ - filename = settings.getValue('pdf_file') - with open(filename) as handle: - data = handle.read() + path = settings.getValue('pdf_file') + data="" + if os.path.exists(path): + with open(path) as handle: + data = handle.read() + else: + if (path.find("github.com") != -1): + path = path.replace("github.com", "raw.githubusercontent.com") + path = path.replace("/blob", "") + try: + resp = requests.get(path) + if resp.status_code == requests.codes.ok: + data = resp.text + except: + raise Exception(f"Invalid path: {path}") try: pdf = json.loads(data) @@ -35,6 +49,6 @@ def load_pdf(): try: pdf = yaml.safe_load(data) except yaml.parser.ParserError: - raise Exception(f"Invalid PDF file: {filename}") + raise Exception(f"Invalid PDF file: {path}") settings.setValue('pdf_file', pdf) |