{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Create a WebarchivSession Object with convenience methods for easy access with your API-Key " ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "from webarchiv import WebarchivSession\n", "\n", "apikey = '2pm8i0hnmpcTK4Oj4CUeBoZd7vywrm4c'\n", "w = WebarchivSession(apikey)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Submit a URL search to get all archived capturedates of the requested URL" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "url = \"http://www.onb.ac.at\"\n", "response = w.wayback_search(url)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The search always returns the full response. Checking for status_code 200 before extracting the response is always a good idea" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "if response.status_code != 200:\n", " print(\"Something went wrong ...\")\n", " exit(1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now it is safe to extract the response\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get the total number of captures of the requested URL" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2483\n" ] } ], "source": [ "print(response.json()['total'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get the Archiveurl of the oldest Capuredate of the requested URL" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "https://webarchiv.onb.ac.at/web/20090916183601/http://www.onb.ac.at\n" ] } ], "source": [ "capturedate = response.json()['hits'][0]['c']\n", "\n", "captureurl = 'https://webarchiv.onb.ac.at/web/' + capturedate + '/' + url\n", "\n", "print (captureurl)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.5" } }, "nbformat": 4, "nbformat_minor": 1 }