diff --git a/content/DNB_SRU_Tutorial_Einstieg.ipynb b/content/DNB_SRU_Tutorial_Einstieg.ipynb deleted file mode 100644 index d1a4a8b..0000000 --- a/content/DNB_SRU_Tutorial_Einstieg.ipynb +++ /dev/null @@ -1,168 +0,0 @@ -{ - "metadata": { - "anaconda-cloud": {}, - "kernelspec": { - "name": "python", - "display_name": "Python (Pyodide)", - "language": "python" - }, - "language_info": { - "codemirror_mode": { - "name": "python", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8" - } - }, - "nbformat_minor": 4, - "nbformat": 4, - "cells": [ - { - "cell_type": "markdown", - "source": "# DNBLab Jupyter Notebook zur SRU Abfrage", - "metadata": { - "nbpresent": { - "id": "d0d72cd5-034d-4b94-a4e2-54f7753cb9f0" - } - } - }, - { - "cell_type": "markdown", - "source": "## SRU - Schnittstellenabfrage, Datenauslieferung und Ergebnisanzeige", - "metadata": { - "nbpresent": { - "id": "558898c3-e162-4e46-92d5-b4c914325790" - } - } - }, - { - "cell_type": "markdown", - "source": "Lassen Sie uns gemeinsam folgenden Markdown *hier* einfügen:", - "metadata": {} - }, - { - "cell_type": "markdown", - "source": "Dieses DNBLab-Tutorial beschreibt eine Beispielabfrage über die SRU-Schnittstelle mit Python. In der Jupyter Notebook Umgebung kann der dokumentierte Code direkt ausgeführt und angepasst werden. Das Tutorial umfasst die exemplarische Abfrage und Ausgabe der Daten in MARC21-xml zur weiteren Verarbeitung mit Python. ", - "metadata": { - "nbpresent": { - "id": "ee78241c-36e7-45e6-b015-0ef46f1e777d" - } - } - }, - { - "cell_type": "markdown", - "source": "## Ganz wichtig, Zwischenspeichern nicht vergessen!", - "metadata": {} - }, - { - "cell_type": "markdown", - "source": "## Arbeitsumgebung einrichten! ", - "metadata": { - "nbpresent": { - "id": "3c6f6024-cb7c-4b65-8646-a753069cb5a4" - }, - "tags": [] - } - }, - { - "cell_type": "code", - "source": "import urllib.parse\nfrom pyodide.http import open_url, pyfetch\nfrom js import fetch\nfrom bs4 import BeautifulSoup as soup\nimport unicodedata\nfrom lxml import etree\nimport pandas as pd", - "metadata": { - "trusted": true - }, - "execution_count": 1, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": "## Abfrage über alle Datensätze... ", - "metadata": {} - }, - { - "cell_type": "code", - "source": "async def dnb_sru(query):\n \n base_url = \"https://services.dnb.de/sru/dnb\"\n params = {'recordSchema' : 'MARC21-xml',\n 'operation': 'searchRetrieve',\n 'version': '1.1',\n 'maximumRecords': '100',\n 'query': query\n }\n \n r = await fetch(base_url + \"?\" + urllib.parse.urlencode(params)) \n r_text = await r.text()\n xml = soup(r_text, features=\"xml\")\n records = xml.find_all('record', {'type':'Bibliographic'})\n \n \n if len(records) < 100:\n \n return records\n \n else:\n \n num_results = 100\n i = 101\n while num_results == 100:\n \n params.update({'startRecord': i})\n r = await fetch(base_url + \"?\" + urllib.parse.urlencode(params)) \n r_text = await r.text()\n xml = soup(r_text, features=\"xml\")\n new_records = xml.find_all('record', {'type':'Bibliographic'})\n records+=new_records\n i+=100\n num_results = len(new_records)\n \n return records", - "metadata": { - "trusted": true - }, - "execution_count": 2, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": "## Felder Titel und Links zu den Objekten durchsuchen... ", - "metadata": {} - }, - { - "cell_type": "code", - "source": "def parse_record(record):\n \n ns = {\"marc\":\"http://www.loc.gov/MARC21/slim\"}\n xml = etree.fromstring(unicodedata.normalize(\"NFC\", str(record)))\n \n #idn\n idn = xml.xpath(\"marc:controlfield[@tag = '001']\", namespaces=ns)\n try:\n idn = idn[0].text\n except:\n idn = 'fail'\n \n # link\n link = xml.xpath(\"marc:datafield[@tag = '856']/marc:subfield[@code = 'u']\", namespaces=ns)\n \n try:\n link = link[0].text\n #titel = unicodedata.normalize(\"NFC\", titel)\n except:\n link = \"unkown\"\n \n # titel\n titel = xml.xpath(\"marc:datafield[@tag = '245']/marc:subfield[@code = 'a']\", namespaces=ns)\n \n try:\n titel = titel[0].text\n #titel = unicodedata.normalize(\"NFC\", titel)\n except:\n titel = \"unkown\"\n \n \n meta_dict = {\"idn\":idn,\n \"titel\":titel,\n \"link\":link}\n \n return meta_dict", - "metadata": { - "trusted": true - }, - "execution_count": 15, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": "# Abfrage nach Suchwort \"Biene\" im Titel + Links zu frei verfügbaren Objekten!", - "metadata": {} - }, - { - "cell_type": "code", - "source": "records = await dnb_sru('tit=Biene and location=onlinefree')\nprint(len(records), 'Ergebnisse')", - "metadata": { - "trusted": true - }, - "execution_count": 16, - "outputs": [ - { - "name": "stdout", - "text": "17 Ergebnisse\n", - "output_type": "stream" - } - ] - }, - { - "cell_type": "markdown", - "source": "## Anzeige der Treffer in einer Tabelle... ", - "metadata": {} - }, - { - "cell_type": "code", - "source": "output = [parse_record(record) for record in records]\ndf = pd.DataFrame(output)\ndf", - "metadata": { - "trusted": true - }, - "execution_count": 17, - "outputs": [ - { - "execution_count": 17, - "output_type": "execute_result", - "data": { - "text/plain": " idn titel \\\n0 1283345676 Verkauf der \"Biene\" an Franz Wagner in Leipzig... \n1 1299731961 Die Biene und der Blitz - die eigenwillige K... \n2 1246522276 Info Bee at UNICARagil: Support from Above for... \n3 1213898609 Die Biene - Illustrierte Schüler*inarbeit - ... \n4 1156534089 Aus der Wabe in die Welt: Biene macht Kultur. ... \n5 118258280X [Rezension zu:] Viel, Bernhard: Der Honigsamml... \n6 1095550535 [Referentenmaterial] / Gesellschaft zur Verbre... \n7 1263070647 Harald Weiss (Hg.): 100 Jahre Biene Maja: Vom ... \n8 1076865429 Harald Weiss (Hg.): 100 Jahre Biene Maja: Vom ... \n9 1046981080 Biene und Honig im pharaonischen Ägypten \n10 1026527112 Temperature effects on the development in the ... \n11 1081225548 Futterqualität und Rekrutierungsverhalten bei ... \n12 1171169078 Die Biene und ihre Zucht \n13 1123508119 Leben und Zucht der Honigbiene \n14 1171169027 Melitto-Theologia : die Verherrlichung des glo... \n15 1119154553 Die italienische Biene und ihre Zucht \n16 1138282669 Nektar – Biene – Honig \n\n link \n0 https://nbn-resolving.org/urn:nbn:de:101:1-202... \n1 https://nbn-resolving.org/urn:nbn:de:bvb:384-o... \n2 https://doi.org/10.18154/RWTH-2021-10614 \n3 https://doi.org/10.18442/140 \n4 https://nbn-resolving.org/urn:nbn:de:bvb:20-op... \n5 https://nbn-resolving.org/urn:nbn:de:hebis:30:... \n6 https://nbn-resolving.org/urn:nbn:de:101:1-201... \n7 https://doi.org/10.17192/ep2015.2.3594 \n8 https://doi.org/10.17192/ep2015.2.3594 \n9 https://nbn-resolving.org/urn:nbn:de:hebis:77-... \n10 https://nbn-resolving.org/urn:nbn:de:bvb:355-e... \n11 https://nbn-resolving.org/urn:nbn:de:hebis:30-... \n12 https://nbn-resolving.org/urn:nbn:de:hebis:30-... \n13 https://nbn-resolving.org/urn:nbn:de:hebis:30-... \n14 https://nbn-resolving.org/urn:nbn:de:hebis:30-... \n15 https://nbn-resolving.org/urn:nbn:de:hebis:30-... \n16 https://nbn-resolving.org/urn:nbn:de:hbz:6-592... ", - "text/html": "
\n | idn | \ntitel | \nlink | \n
---|---|---|---|
0 | \n1283345676 | \nVerkauf der \"Biene\" an Franz Wagner in Leipzig... | \nhttps://nbn-resolving.org/urn:nbn:de:101:1-202... | \n
1 | \n1299731961 | \nDie Biene und der Blitz - die eigenwillige K... | \nhttps://nbn-resolving.org/urn:nbn:de:bvb:384-o... | \n
2 | \n1246522276 | \nInfo Bee at UNICARagil: Support from Above for... | \nhttps://doi.org/10.18154/RWTH-2021-10614 | \n
3 | \n1213898609 | \nDie Biene - Illustrierte Schüler*inarbeit - ... | \nhttps://doi.org/10.18442/140 | \n
4 | \n1156534089 | \nAus der Wabe in die Welt: Biene macht Kultur. ... | \nhttps://nbn-resolving.org/urn:nbn:de:bvb:20-op... | \n
5 | \n118258280X | \n[Rezension zu:] Viel, Bernhard: Der Honigsamml... | \nhttps://nbn-resolving.org/urn:nbn:de:hebis:30:... | \n
6 | \n1095550535 | \n[Referentenmaterial] / Gesellschaft zur Verbre... | \nhttps://nbn-resolving.org/urn:nbn:de:101:1-201... | \n
7 | \n1263070647 | \nHarald Weiss (Hg.): 100 Jahre Biene Maja: Vom ... | \nhttps://doi.org/10.17192/ep2015.2.3594 | \n
8 | \n1076865429 | \nHarald Weiss (Hg.): 100 Jahre Biene Maja: Vom ... | \nhttps://doi.org/10.17192/ep2015.2.3594 | \n
9 | \n1046981080 | \nBiene und Honig im pharaonischen Ägypten | \nhttps://nbn-resolving.org/urn:nbn:de:hebis:77-... | \n
10 | \n1026527112 | \nTemperature effects on the development in the ... | \nhttps://nbn-resolving.org/urn:nbn:de:bvb:355-e... | \n
11 | \n1081225548 | \nFutterqualität und Rekrutierungsverhalten bei ... | \nhttps://nbn-resolving.org/urn:nbn:de:hebis:30-... | \n
12 | \n1171169078 | \nDie Biene und ihre Zucht | \nhttps://nbn-resolving.org/urn:nbn:de:hebis:30-... | \n
13 | \n1123508119 | \nLeben und Zucht der Honigbiene | \nhttps://nbn-resolving.org/urn:nbn:de:hebis:30-... | \n
14 | \n1171169027 | \nMelitto-Theologia : die Verherrlichung des glo... | \nhttps://nbn-resolving.org/urn:nbn:de:hebis:30-... | \n
15 | \n1119154553 | \nDie italienische Biene und ihre Zucht | \nhttps://nbn-resolving.org/urn:nbn:de:hebis:30-... | \n
16 | \n1138282669 | \nNektar – Biene – Honig | \nhttps://nbn-resolving.org/urn:nbn:de:hbz:6-592... | \n