Kaynağa Gözat

better skeleton

master
Dimitri Merejkowsky 5 yıl önce
ebeveyn
işleme
4a85c25f51
2 değiştirilmiş dosya ile 27 ekleme ve 5 silme
  1. +1
    -1
      marvel/.gitignore
  2. +26
    -4
      marvel/hello.py

+ 1
- 1
marvel/.gitignore Dosyayı Görüntüle

@@ -1 +1 @@
api-keys
api-keys.txt

+ 26
- 4
marvel/hello.py Dosyayı Görüntüle

@@ -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__":