{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exploring facets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Facets aggregate collection data in interesting and useful ways, allowing us to build pictures of the collection. This notebook shows you how to get facet data from Trove." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "RendererRegistry.enable('notebook')" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import requests\n", "import altair as alt\n", "import pandas as pd\n", "import os\n", "\n", "# Make sure data directory exists\n", "os.makedirs('data', exist_ok=True)\n", "\n", "alt.renderers.enable('notebook')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Insert your API key between the quotes." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Your API key is: \n" ] } ], "source": [ "api_key = ''\n", "print('Your API key is: {}'.format(api_key))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "api_search_url = 'https://api.trove.nla.gov.au/result'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set up our query parameters. We want everything, so we set the `q` parameter to be a single space." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "params = {\n", " 'q': ' ', # A space to search for everything\n", " 'facet': 'format',\n", " 'zone': 'book', \n", " 'key': api_key,\n", " 'encoding': 'json',\n", " 'n': 1\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "response = requests.get(api_search_url, params=params)\n", "print(response.url) # This shows us the url that's sent to the API\n", "data = response.json()\n", "# print(data)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | facet | \n", "total | \n", "
---|---|---|
0 | \n", "Archived website | \n", "21976 | \n", "
1 | \n", "Audio book | \n", "181878 | \n", "
2 | \n", "Book/Braille | \n", "30639 | \n", "
3 | \n", "Book/Illustrated | \n", "8866768 | \n", "
4 | \n", "Book/Large print | \n", "104565 | \n", "
5 | \n", "Book | \n", "9240406 | \n", "
6 | \n", "Conference Proceedings | \n", "576807 | \n", "
7 | \n", "Microform | \n", "702354 | \n", "
8 | \n", "Thesis | \n", "584371 | \n", "