Newer
Older
{
"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": [
"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",
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"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",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
]
}
],
"source": [
"print(response.json()['total'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Get the Archiveurl of the oldest Capuredate of the requested URL"
]
},
{
"cell_type": "code",
"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
}