|
|
@@ -1,17 +1,23 @@ |
|
|
|
import hashlib |
|
|
|
import requests |
|
|
|
import shutil |
|
|
|
import time |
|
|
|
import textwrap |
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
with open("api-keys", "r") as file: |
|
|
|
# Read api keys from the text file |
|
|
|
with open("api-keys.txt", "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" |
|
|
|
# base url |
|
|
|
base_url = "http://gateway.marvel.com/v1/public" |
|
|
|
|
|
|
|
# Authorizsation stuff |
|
|
|
params = dict() |
|
|
|
params["apikey"] = public_key |
|
|
|
ts = str(time.time()) |
|
|
@@ -21,9 +27,25 @@ def main(): |
|
|
|
digest = hasher.hexdigest() |
|
|
|
params["ts"] = ts |
|
|
|
params["hash"] = digest |
|
|
|
|
|
|
|
|
|
|
|
# Other parameters: |
|
|
|
name = "Spider-Man" |
|
|
|
params["name"] = name |
|
|
|
|
|
|
|
|
|
|
|
# Perform the request |
|
|
|
url = base_url + "/characters" |
|
|
|
response = requests.get(url, params=params) |
|
|
|
print(response.status_code) |
|
|
|
print(response.text) |
|
|
|
status_code = response.status_code |
|
|
|
assert status_code == 200, "got status: " + str(status_code) |
|
|
|
body = response.json() |
|
|
|
description = body["data"]["results"][0]["description"] |
|
|
|
|
|
|
|
# Print the description |
|
|
|
terminal_size = shutil.get_terminal_size() |
|
|
|
columns = terminal_size.columns |
|
|
|
print("\n".join(textwrap.wrap(description, width=columns))) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|