21 lines
No EOL
638 B
Text
21 lines
No EOL
638 B
Text
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"]
|
|
alt = req.json()["alt"]
|
|
print(f"xkcd {e}: {title} ⁜ {alt} ⁜ https://xkcd.com/{e}")
|
|
else:
|
|
print("Couldn't fetch: status code {req.status_code}")
|
|
else:
|
|
print("Argument must be a number") |