{ "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": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import datetime\n", "from webarchiv import WebarchivSession\n", "\n", "apikey = 'Zz2tQls7fuaocX2pjrfc2npojqbGwXL2'\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": 2, "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": 18, "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": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2473\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": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "https://webarchiv.onb.ac.at/web/20090916183601/http://www.onb.ac.at\n" ] } ], "source": [ "capturedate = datetime.datetime.fromtimestamp(response.json()['hits'][0]['c']).strftime('%Y%m%d%H%M%S')\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 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }