#!/usr/bin/env python3 #This script will get and print customer usage data import requests import datetime import json import base64 import hashlib import hmac publicKey = 'PUBLIC_KEY_HERE' privateKey = 'PRIVATE_KEY_HERE' def generate_auth_header(abs_path, http_method, private_key, public_key, time_stamp): string2hash = http_method + abs_path + time_stamp bkey = bytes(source=private_key, encoding='UTF-8') bpayload = bytes(source=string2hash, encoding='UTF-8') hmacsha1 = hmac.new(bkey, bpayload, hashlib.sha1).digest() base64encoded = base64.b64encode(hmacsha1).decode('UTF-8') auth_header = f'OWL {public_key}:{base64encoded}' return auth_header ##url params host = 'api.darkowl.com' endpoint = '/api/v1/usage' url = f'https://{host}{endpoint}' absPath = endpoint date = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT') auth = generate_auth_header(absPath, 'GET', privateKey, publicKey, date) headers = {'Authorization': auth, 'X-VISION-DATE': date, 'Accept': 'application/json'} r = requests.get(url, headers=headers) if r.status_code == 200: print(json.dumps(r.json(), indent=4)) else: print(f'Status {r.status_code}') print(r.text)