Commit 3af3760b authored by Stefan Karner's avatar Stefan Karner

Add tracking fingerprint

parent e3f3cbee
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'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment