Last active
September 30, 2024 20:11
-
-
Save juandesant/81f2f3bd2b1b5e6752f62809262a3ab8 to your computer and use it in GitHub Desktop.
Generation of URL for Jama Search for a particular input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys # we use sys to get the input to the service | |
# from sys.stdin | |
from urllib.parse import quote # to convert high-ASCII and other | |
# into URL-compatible quoting | |
import webbrowser # To open the web browser | |
# establish the base instance URL | |
jama_search_base_url = "https://almaobservatory.jamacloud.com/perspective.req#/" | |
project_id="project_id code" | |
# get the text from the selection, split it in lines, URL quote it each one, | |
# and open the resulting search URL in a different tab | |
for line in sys.stdin: | |
text_input = quote(line.rstrip("\n")) # rstrip removes the ends of line | |
# URL for the Jama Search; you can use alternatively the PROJECT scope with a project_id | |
jama_search_url = jama_search_base_url + f"search?term={text_input}&scope=GLOBAL" | |
# jama_search_url = jama_search_base_url + f"search?term={text_input}&project={project_id}&scope=PROJECT" | |
# Output of the workflow done by a print | |
print(jama_search_url) | |
# Open the browser using Python's native browser support | |
# in a new tab (new=2) in the background (autoraise=False) | |
webbrowser.open(jama_search_url, new=2, autoraise=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code assumes that the search term is coming from standard input. The result URL is sent to the default web browser using the
webbrowser
Python module. You will need to set the right Jama URL in thejama_search_base_url
variable.