Spaces:
Sleeping
Sleeping
Download case_study_pipeline/ezproxy.py from UWRFR/UWaterlooRFRChatBot: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/spaces/UWRFR/UWaterlooRFRChatBot/resolve/main/case_study_pipeline/ezproxy.py
- Command line
-
hf download hf://spaces/UWRFR/UWaterlooRFRChatBot/case_study_pipeline/ezproxy.py
-
curl -L -o ezproxy.py https://huggingface.co/spaces/UWRFR/UWaterlooRFRChatBot/resolve/main/case_study_pipeline/ezproxy.py
1.44 kB
| """ | |
| ezproxy.py — UWaterloo EZproxy URL helper. | |
| UWaterloo's EZproxy uses "domain dash-translation": any publisher hostname | |
| can be proxied by replacing dots with dashes and appending | |
| ".proxy.lib.uwaterloo.ca". E.g.: | |
| link.springer.com -> link-springer-com.proxy.lib.uwaterloo.ca | |
| agupubs.onlinelibrary.wiley.com -> agupubs-onlinelibrary-wiley-com.proxy.lib.uwaterloo.ca | |
| This only grants access if you already have an authenticated EZproxy | |
| session in the browser (see case_study_pipeline/README.md for the one-time | |
| login + the Chrome-assisted download procedure). | |
| """ | |
| from __future__ import annotations | |
| from urllib.parse import urlparse, urlunparse | |
| EZPROXY_SUFFIX = ".proxy.lib.uwaterloo.ca" | |
| def to_ezproxy_url(article_url: str) -> str: | |
| """Convert a publisher article URL into its UWaterloo EZproxy equivalent.""" | |
| parsed = urlparse(article_url) | |
| dashed_host = parsed.netloc.replace(".", "-") | |
| proxied_netloc = dashed_host + EZPROXY_SUFFIX | |
| return urlunparse(parsed._replace(netloc=proxied_netloc)) | |
| def doi_redirect_url(doi: str) -> str: | |
| """The DOI resolver URL — navigating here redirects to the publisher's page.""" | |
| return "https://doi.org/{}".format(doi) | |
| if __name__ == "__main__": | |
| import sys | |
| if len(sys.argv) != 2: | |
| print("Usage: python3 -m case_study_pipeline.ezproxy <publisher_article_url>") | |
| sys.exit(1) | |
| print(to_ezproxy_url(sys.argv[1])) | |