diff --git a/cc/xkcd b/cc/xkcd new file mode 100644 index 0000000..4fdd9ea --- /dev/null +++ b/cc/xkcd @@ -0,0 +1,20 @@ +import requests, sys +if len(sys.argv) != 4: + print("Only takes 1 arg - number") +else: + try: + e = int(sys.argv[3]) + isnum = True + except: + isnum = False + if isnum: + req = requests.get(f"https://xkcd.com/{e}/info.0.json") + if req.status_code == 404: + print("Comic not found.") + elif req.ok: + title = req.json()["title"] + print(f"XKCD {e}: {title} (https://xkcd.com/{e})") + else: + print("Couldn't fetch: status code {req.status_code}") + else: + print("Argument must be a number") \ No newline at end of file