Add cc/xkcd

This commit is contained in:
Nova Cat 2025-03-21 21:28:10 -07:00
parent 851c37be70
commit acd935f44a

20
cc/xkcd Normal file
View file

@ -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")