parent
851c37be70
commit
acd935f44a
1 changed files with 20 additions and 0 deletions
20
cc/xkcd
Normal file
20
cc/xkcd
Normal 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")
|
Loading…
Add table
Reference in a new issue