Skip to content
Commits on Source (2)
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Create a WebarchivSession Object with convenience methods for easy access with your API-Key Create a WebarchivSession Object with convenience methods for easy access with your API-Key
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import datetime
from webarchiv import WebarchivSession from webarchiv import WebarchivSession
apikey = 'Zz2tQls7fuaocX2pjrfc2npojqbGwXL2' apikey = 'Zz2tQls7fuaocX2pjrfc2npojqbGwXL2'
w = WebarchivSession(apikey) w = WebarchivSession(apikey)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Submit a URL search to get all archived capturedates of the requested URL Submit a URL search to get all archived capturedates of the requested URL
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
url = "http://www.onb.ac.at" url = "http://www.onb.ac.at"
response = w.wayback_search(url) response = w.wayback_search(url)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
The search always returns the full response. Checking for status_code 200 before extracting the response is always a good idea The search always returns the full response. Checking for status_code 200 before extracting the response is always a good idea
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
if response.status_code != 200: if response.status_code != 200:
print("Something went wrong ...") print("Something went wrong ...")
exit(1) exit(1)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Now it is safe to extract the response Now it is safe to extract the response
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Get the total number of captures of the requested URL Get the total number of captures of the requested URL
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
print(response.json()['total']) print(response.json()['total'])
``` ```
%% Output %% Output
2426 2473
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Get the Archiveurl of the oldest Capuredate of the requested URL Get the Archiveurl of the oldest Capuredate of the requested URL
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
capturedate = datetime.datetime.fromtimestamp(response.json()['hits'][0]['c']).strftime('%Y%m%d%H%M%S') capturedate = datetime.datetime.fromtimestamp(response.json()['hits'][0]['c']).strftime('%Y%m%d%H%M%S')
captureurl = 'https://webarchiv.onb.ac.at/web/' + capturedate + '/' + url captureurl = 'https://webarchiv.onb.ac.at/web/' + capturedate + '/' + url
print (captureurl) print (captureurl)
``` ```
%% Output %% Output
https://webarchiv.onb.ac.at/web/20090916183601/http://www.onb.ac.at https://webarchiv.onb.ac.at/web/20090916183601/http://www.onb.ac.at
%% Cell type:code id: tags:
``` python
```
......
This diff is collapsed.
...@@ -18,6 +18,15 @@ class WebarchivSession: ...@@ -18,6 +18,15 @@ class WebarchivSession:
""" """
return '0.1.0' return '0.1.0'
@property
def api_path(self):
"""
Protocol, domain and path prefix for the Webarchive API,
with a single positional format string placeholder
for the REST operation and parameters.
"""
return 'https://webarchiv.onb.ac.at/api/'
@property @property
def base_url(self): def base_url(self):
""" """
...@@ -25,7 +34,7 @@ class WebarchivSession: ...@@ -25,7 +34,7 @@ class WebarchivSession:
with a single positional format string placeholder with a single positional format string placeholder
for the REST operation and parameters. for the REST operation and parameters.
""" """
return 'https://webarchiv.onb.ac.at/api/{}' return self.api_path + '/{}'
@property @property
def _error_template(self): def _error_template(self):
...@@ -239,6 +248,8 @@ class WebarchivSession: ...@@ -239,6 +248,8 @@ class WebarchivSession:
self._display_http_error(e) self._display_http_error(e)
print('Error:'.format(query_string)) print('Error:'.format(query_string))
def getSnapshotUrl(self, id):
return self.api_path + 'snapshot/' + id + "?t=" + self.token + "&apikey=" + self.api_key;
if __name__ == '__main__': if __name__ == '__main__':
# noinspection SpellCheckingInspection # noinspection SpellCheckingInspection
......