From 55847e69ae71b3745b19138bdc8e43a180624da1 Mon Sep 17 00:00:00 2001 From: Dimitri Merejkowsky Date: Fri, 1 Mar 2019 20:23:07 +0100 Subject: [PATCH] Skeleton for playing with marvel API --- marvel/.gitignore | 1 + marvel/hello.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 marvel/.gitignore create mode 100644 marvel/hello.py diff --git a/marvel/.gitignore b/marvel/.gitignore new file mode 100644 index 0000000..fbbda11 --- /dev/null +++ b/marvel/.gitignore @@ -0,0 +1 @@ +api-keys diff --git a/marvel/hello.py b/marvel/hello.py new file mode 100644 index 0000000..f3c69b1 --- /dev/null +++ b/marvel/hello.py @@ -0,0 +1,30 @@ +import hashlib +import requests +import time + + +def main(): + with open("api-keys", "r") as file: + lines = file.readlines() + assert len(lines) == 2, "Incorrect api-keys file" + public_key = lines[0].strip() + private_key = lines[1].strip() + + + url = "http://gateway.marvel.com/v1/public/comics" + params = dict() + params["apikey"] = public_key + ts = str(time.time()) + to_hash = ts + private_key + public_key + hasher = hashlib.md5() + hasher.update(to_hash.encode()) + digest = hasher.hexdigest() + params["ts"] = ts + params["hash"] = digest + response = requests.get(url, params=params) + print(response.status_code) + print(response.text) + + +if __name__ == "__main__": + main()