{ "cells": [ { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "# Create a Trove OCR corrections ticker" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "%%capture\n", "import os\n", "import time\n", "\n", "import requests\n", "from dotenv import load_dotenv\n", "from IPython.display import HTML, clear_output, display\n", "\n", "load_dotenv()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "# Insert your Trove API key\n", "API_KEY = \"YOUR API KEY\"\n", "\n", "# Use api key value from environment variables if it is available\n", "if os.getenv(\"TROVE_API_KEY\"):\n", " API_KEY = os.getenv(\"TROVE_API_KEY\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "params = {\"q\": \"has:corrections\", \"category\": \"newspaper\", \"encoding\": \"json\", \"n\": \"0\"}\n", "\n", "headers = {\"X-API-KEY\": API_KEY}" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "def update_corrections():\n", " try:\n", " while True:\n", " clear_output(wait=True)\n", " response = requests.get(\n", " \"http://api.trove.nla.gov.au/v3/result\", params=params, headers=headers\n", " )\n", " data = response.json()\n", " total = int(data[\"category\"][0][\"records\"][\"total\"])\n", " display(\n", " HTML(\n", " '
Trove users have made corrections to {:,} newspaper articles.
'.format(\n", " total\n", " )\n", " )\n", " )\n", " time.sleep(5)\n", " except KeyboardInterrupt:\n", " pass" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [ "nbval-skip" ] }, "outputs": [], "source": [ "# Run this cell to start the ticker\n", "# To stop, click the stop button or select Kernel > Interrupt from the menu\n", "update_corrections()" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "----\n", "\n", "Created by [Tim Sherratt](https://timsherratt.org/) for the [GLAM Workbench](https://glam-workbench.github.io/). \n", "Support this project by becoming a [GitHub sponsor](https://github.com/sponsors/wragge?o=esb)." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" }, "rocrate": { "author": [ { "mainEntityOfPage": "https://timsherratt.au", "name": "Sherratt, Tim", "orcid": "https://orcid.org/0000-0001-7956-4498" } ], "description": "Uses the has:corrections parameter to get the total number of newspaper articles with OCR corrections, then displays the results, updating every five seconds.", "mainEntityOfPage": "https://glam-workbench.net/trove-newspapers/Create-a-Trove-corrections-ticker/", "name": "Create a Trove OCR corrections ticker" } }, "nbformat": 4, "nbformat_minor": 4 }