Spaces:
Runtime error
Runtime error
Update InitialMarkups.py
Browse files- InitialMarkups.py +14 -12
InitialMarkups.py
CHANGED
|
@@ -35,6 +35,9 @@ import copy
|
|
| 35 |
import tsadropboxretrieval
|
| 36 |
|
| 37 |
import json, urllib.parse, copy
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
def changepdflinks(data_list_JSON, pdflink):
|
| 40 |
print('Received JSON:', data_list_JSON)
|
|
@@ -48,7 +51,6 @@ def changepdflinks(data_list_JSON, pdflink):
|
|
| 48 |
elif not isinstance(data_list_JSON, list):
|
| 49 |
raise ValueError(f"Input must be JSON string or list, got {type(data_list_JSON)}")
|
| 50 |
|
| 51 |
-
# Work on a safe copy
|
| 52 |
data_list_JSON = copy.deepcopy(data_list_JSON)
|
| 53 |
|
| 54 |
for entry in data_list_JSON:
|
|
@@ -57,21 +59,21 @@ def changepdflinks(data_list_JSON, pdflink):
|
|
| 57 |
continue
|
| 58 |
|
| 59 |
parsed = urllib.parse.urlparse(old_url)
|
| 60 |
-
|
| 61 |
-
# Extract page/zoom fragment (if present)
|
| 62 |
fragment = parsed.fragment # e.g. "page=3&zoom=150"
|
| 63 |
-
print(fragment)
|
| 64 |
-
# Encode the new pdf link safely
|
| 65 |
-
encoded_pdf = urllib.parse.quote(pdflink, safe=":/?=&")
|
| 66 |
|
| 67 |
-
#
|
|
|
|
|
|
|
|
|
|
| 68 |
if fragment:
|
| 69 |
-
new_url = f"{encoded_pdf}#{fragment}"
|
| 70 |
else:
|
| 71 |
-
new_url = encoded_pdf
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
| 75 |
return data_list_JSON
|
| 76 |
|
| 77 |
|
|
|
|
| 35 |
import tsadropboxretrieval
|
| 36 |
|
| 37 |
import json, urllib.parse, copy
|
| 38 |
+
import json
|
| 39 |
+
import copy
|
| 40 |
+
import urllib.parse
|
| 41 |
|
| 42 |
def changepdflinks(data_list_JSON, pdflink):
|
| 43 |
print('Received JSON:', data_list_JSON)
|
|
|
|
| 51 |
elif not isinstance(data_list_JSON, list):
|
| 52 |
raise ValueError(f"Input must be JSON string or list, got {type(data_list_JSON)}")
|
| 53 |
|
|
|
|
| 54 |
data_list_JSON = copy.deepcopy(data_list_JSON)
|
| 55 |
|
| 56 |
for entry in data_list_JSON:
|
|
|
|
| 59 |
continue
|
| 60 |
|
| 61 |
parsed = urllib.parse.urlparse(old_url)
|
|
|
|
|
|
|
| 62 |
fragment = parsed.fragment # e.g. "page=3&zoom=150"
|
| 63 |
+
print("Fragment:", fragment)
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
# Encode the provided PDF link for safe use in query string
|
| 66 |
+
encoded_pdf = urllib.parse.quote(pdflink, safe='')
|
| 67 |
+
|
| 68 |
+
# Build final view link
|
| 69 |
if fragment:
|
| 70 |
+
new_url = f"https://findconsole-initialmarkups.hf.space/view-pdf?pdfLink={encoded_pdf}#{fragment}"
|
| 71 |
else:
|
| 72 |
+
new_url = f"https://findconsole-initialmarkups.hf.space/view-pdf?pdfLink={encoded_pdf}"
|
| 73 |
+
|
| 74 |
+
print("New URL:", new_url)
|
| 75 |
+
entry["NBSLink"] = new_url
|
| 76 |
+
|
| 77 |
return data_list_JSON
|
| 78 |
|
| 79 |
|