Skip to content

Instantly share code, notes, and snippets.

@juandesant
Last active September 30, 2024 20:11
Show Gist options
  • Save juandesant/81f2f3bd2b1b5e6752f62809262a3ab8 to your computer and use it in GitHub Desktop.
Save juandesant/81f2f3bd2b1b5e6752f62809262a3ab8 to your computer and use it in GitHub Desktop.
Generation of URL for Jama Search for a particular input
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)
@juandesant
Copy link
Author

juandesant commented Sep 30, 2024

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 the jama_search_base_url variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment