Skip to content

Instantly share code, notes, and snippets.

@danmackinlay
Last active December 11, 2024 03:07
Show Gist options
  • Save danmackinlay/d92a30f40c2ae36e8af72bd6c02947dd to your computer and use it in GitHub Desktop.
Save danmackinlay/d92a30f40c2ae36e8af72bd6c02947dd to your computer and use it in GitHub Desktop.
Search rijksmuseum prints in English

Search rijksmuseum prints in english

Rijksmuseum's online collection is amazing but their search defaults do not suit me.

This script automates searching using my favourite options (restrict to prints, visible online)

Features

  • Translates English search terms into Dutch
  • Opens the Rijksmuseum search results directly in your browser

Installation

Prerequisites

  • Python 3.6+: Ensure Python is installed on your machine. Check with:
    python --version
  • Dependencies: Install the required Python packages by running:
    pip install -r requirements.txt

Usage

  1. Run the Script: Pass your search terms in English from the command line.

    python rijks_search.py "your search term here"

    Example:

    python rijks_search.py "still life painting"
  2. Output: The script will automatically:

    • Translate the search term into Dutch
    • Open your default browser with the Rijksmuseum search results for the translated term

Example

python rijks_search.py "still life with flowers"

This command will:

  • Translate "still life with flowers" to Dutch
  • Open the translated query in your default browser in the Rijksmuseum search

Troubleshooting

  • Translation Issues: Ensure the translate package is installed and working properly.
  • Browser Issues: The script uses the default browser set on your macOS system. Check your browser settings if the script fails to open the URL.

License

This project is MIT licensed and provided as-is.

#!/usr/bin/env python
import webbrowser
import argparse
from urllib.parse import quote
from translate import Translator
def search_rijksmuseum(query):
# Translate English query to Dutch
translator = Translator(to_lang="nl")
translated_query = translator.translate(query)
# URL encode the translated query
encoded_query = quote(translated_query)
# search_url = f"https://www.rijksmuseum.nl/nl/zoeken?q={encoded_query}&p=2&ps=12&type=prent&imgonly=True&st=Objects&ii=0"
search_url = f"https://www.rijksmuseum.nl/nl/collectie/zoeken?query={encoded_query}&collectionSearchContext=Art&page=1&sortingType=Popularity&facets[0].id=a8ea7a0fd82263755305737ecfad87b4&facets[0].nodeRelationType=HasObjectType"
# Open the search in the browser
webbrowser.open(search_url)
print(f"Opened Rijksmuseum search for: {translated_query}")
if __name__ == "__main__":
# Set up argument parsing
parser = argparse.ArgumentParser(
description="Search Rijksmuseum in Dutch via English input."
)
parser.add_argument("query", nargs="+", help="Search terms in English")
args = parser.parse_args()
# Join the arguments into a single string query
query = " ".join(args.query)
search_rijksmuseum(query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment