From 70722f7e1e63afc1c344751f5dc0d2ab206fb2b0 Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 8 Apr 2019 15:44:10 +0200 Subject: [PATCH] Save Page Sample --- sample8.ipynb | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ webarchiv.py | 21 +++++++++-- 2 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 sample8.ipynb diff --git a/sample8.ipynb b/sample8.ipynb new file mode 100644 index 0000000..7254f5d --- /dev/null +++ b/sample8.ipynb @@ -0,0 +1,99 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "import json" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create a WebarchivSession Object with convenience methods for easy access with your API-Key " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from webarchiv import WebarchivSession\n", + "\n", + "apikey = '2pm8i0hnmpcTK4Oj4CUeBoZd7vywrm4c'\n", + "w = WebarchivSession(apikey)\n" + ] + }, + { + "cell_type": "raw", + "metadata": {}, + "source": [ + "request archiving a Webpage" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'nomination_id': 247, 'seed': 'http://www.onb.ac.at', 'nominationtype': 5}\n" + ] + } + ], + "source": [ + "response = w.savePage(\"http://www.onb.ac.at\")\n", + "\n", + "if response.status_code == 201:\n", + " print(response.json())\n", + "else:\n", + " print(\"Error \", response.status_code)\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "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 +} diff --git a/webarchiv.py b/webarchiv.py index 7aa4202..adb0014 100644 --- a/webarchiv.py +++ b/webarchiv.py @@ -251,15 +251,30 @@ class WebarchivSession: def getSnapshotUrl(self, seed, capture, onlysvg): return self.api_path + 'snapshot?capture=' + capture + '&t=' + self.token + '&apikey=' + self.api_key + '&onlysvg=' + onlysvg + '&seed=' + seed; + def savePage(self, url): + self.connect() + r = requests.post(self.base_url.format('savepage'), + data='''{{ + "apikey": "{api_key}", + "t": "{token}", + "url": "{url}" + }}'''.format(api_key=self.api_key, token=self.token, url=url), + headers={ + 'content-type': 'application/json', + 'accept': 'application/ld+json' + } + ) + return r; + if __name__ == '__main__': # noinspection SpellCheckingInspection w = WebarchivSession('2pm8i0hnmpcTK4Oj4CUeBoZd7vywrm4c') # response = w.wayback_search("http://www.onb.ac.at") # response = w.wayback_search("http://frauenhetz.jetzt") - response = w.histogram_search("Nationalbibliothek Prunksaal Schwarzenegger") -# response = w.wayback_search("x") + #response = w.histogram_search("Nationalbibliothek Prunksaal Schwarzenegger") + response = w.savePage("http://www.onb.ac.at") - if response.status_code == 200: + if response.status_code == 201: print(response.json()) else: print("Error ", response.status_code) -- GitLab