diff --git a/3.3 - IIIF collection from SPARQL.ipynb b/3.1 - IIIF Collection from SPARQL.ipynb similarity index 100% rename from 3.3 - IIIF collection from SPARQL.ipynb rename to 3.1 - IIIF Collection from SPARQL.ipynb diff --git a/4.1 - Webarchive - Interacting with the API.ipynb b/4.1 - Webarchive - Interacting with the API.ipynb index fc5d1ca57fcd5b1e78318a866f38d0a44f6a7d65..e68c12f291b782301666e4e6745a82a51bfeef51 100644 --- a/4.1 - Webarchive - Interacting with the API.ipynb +++ b/4.1 - Webarchive - Interacting with the API.ipynb @@ -922,7 +922,7 @@ }, "outputs": [], "source": [ - "session = webarchiv.WebarchivSession(API_KEY)" + "session = webarchiv.WebarchivSession(API_KEY, allow_tracking=True)" ] }, { diff --git a/webarchiv.py b/webarchiv.py index adb00148b31239e2e740a6f31722f9d53c697fa4..af8caf73329b6a10119c34f47570933782ec1571 100644 --- a/webarchiv.py +++ b/webarchiv.py @@ -1,6 +1,8 @@ import sys import time import requests +import uuid +import hashlib from requests import HTTPError _datetime_format_string = '%Y%m%d%H%M%S' @@ -45,8 +47,9 @@ class WebarchivSession: """ return 'HTTP ERROR - status code {status_code}\n----\n{response_text}\n----\n\n' - def __init__(self, api_key): + def __init__(self, api_key, allow_tracking=False): self.api_key = api_key + self.allow_tracking = allow_tracking self.token = None def connect(self): @@ -59,12 +62,21 @@ class WebarchivSession: self._display_http_error(e) def _authenticate(self): + if self.allow_tracking: + from uuid import getnode as get_mac + mac = get_mac() + sha256 = hashlib.sha256() + sha256.update(str(mac).encode('utf-8')) + fingerprint = sha256.hexdigest() + else: + fingerprint = '' + r = requests.post(self.base_url.format('authentication'), data='''{{ "apikey": "{api_key}", - "fingerprint": "string", + "fingerprint": "{fingerprint}", "version": "{version}" - }}'''.format(api_key=self.api_key, version=self.version), + }}'''.format(api_key=self.api_key, version=self.version, fingerprint=fingerprint), headers={ 'content-type': 'application/json', 'accept': 'application/ld+json'