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\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
idntitellink
01283345676Verkauf der \"Biene\" an Franz Wagner in Leipzig...https://nbn-resolving.org/urn:nbn:de:101:1-202...
11299731961˜Dieœ Biene und der Blitz - die eigenwillige K...https://nbn-resolving.org/urn:nbn:de:bvb:384-o...
21246522276Info Bee at UNICARagil: Support from Above for...https://doi.org/10.18154/RWTH-2021-10614
31213898609˜Dieœ Biene - Illustrierte Schüler*inarbeit - ...https://doi.org/10.18442/140
41156534089Aus der Wabe in die Welt: Biene macht Kultur. ...https://nbn-resolving.org/urn:nbn:de:bvb:20-op...
5118258280X[Rezension zu:] Viel, Bernhard: Der Honigsamml...https://nbn-resolving.org/urn:nbn:de:hebis:30:...
61095550535[Referentenmaterial] / Gesellschaft zur Verbre...https://nbn-resolving.org/urn:nbn:de:101:1-201...
71263070647Harald Weiss (Hg.): 100 Jahre Biene Maja: Vom ...https://doi.org/10.17192/ep2015.2.3594
81076865429Harald Weiss (Hg.): 100 Jahre Biene Maja: Vom ...https://doi.org/10.17192/ep2015.2.3594
91046981080Biene und Honig im pharaonischen Ägyptenhttps://nbn-resolving.org/urn:nbn:de:hebis:77-...
101026527112Temperature effects on the development in the ...https://nbn-resolving.org/urn:nbn:de:bvb:355-e...
111081225548Futterqualität und Rekrutierungsverhalten bei ...https://nbn-resolving.org/urn:nbn:de:hebis:30-...
121171169078˜Dieœ Biene und ihre Zuchthttps://nbn-resolving.org/urn:nbn:de:hebis:30-...
131123508119Leben und Zucht der Honigbienehttps://nbn-resolving.org/urn:nbn:de:hebis:30-...
141171169027Melitto-Theologia : die Verherrlichung des glo...https://nbn-resolving.org/urn:nbn:de:hebis:30-...
151119154553˜Dieœ italienische Biene und ihre Zuchthttps://nbn-resolving.org/urn:nbn:de:hebis:30-...
161138282669Nektar – Biene – Honighttps://nbn-resolving.org/urn:nbn:de:hbz:6-592...
\n
" - }, - "metadata": {} - } - ] - }, - { - "cell_type": "markdown", - "source": "# Speichern der Ergebnisse als CSV-Datei!", - "metadata": {} - }, - { - "cell_type": "code", - "source": "df.to_csv(\"SRU_Titel.csv\", index=False)", - "metadata": { - "trusted": true - }, - "execution_count": 18, - "outputs": [] - } - ] -} \ No newline at end of file