diff --git a/webarchiv.py b/webarchiv.py index 4a60fcdc68dad976ab951140bd6e9d3ae615918a..58a09f70fbe9e35f4ccf5db8b8693df9543f72ba 100644 --- a/webarchiv.py +++ b/webarchiv.py @@ -1,6 +1,7 @@ import sys import time import requests +import hashlib from requests import HTTPError _datetime_format_string = '%Y%m%d%H%M%S' @@ -45,8 +46,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 +61,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'