Last active
January 22, 2025 01:18
-
-
Save aaroncouch/7ff9b86b817452723035384e25160b72 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import time | |
import hmac | |
import hashlib | |
import base64 | |
import requests | |
def get_whalewisdom(secret_key, shared_key, args): | |
"""Simple function to GET WhaleWisdom Data from their API. | |
Args: | |
secret_key (str) : Your secret API key. | |
shared_key (str) : Your shared API key. | |
args (dict): The command to execute. | |
Returns: | |
dict: Returns a dictionary object containing data retrieved from a successful API call. | |
""" | |
args_str = json.dumps(args) | |
curr_time = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) | |
hmac_hash = hmac.new( | |
secret_key.encode(), f"{args_str}\n{curr_time}".encode(), hashlib.sha1 | |
).digest() | |
signature = base64.b64encode(hmac_hash).rstrip() | |
response = requests.get( | |
url="https://whalewisdom.com/shell/command.json", | |
params={ | |
"args": args_str, | |
"api_shared_key": shared_key, | |
"api_sig": signature.decode(), | |
"timestamp": curr_time, | |
}, | |
) | |
response.raise_for_status() | |
return response.json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment