We like to post xkcd comics here. So I decided to make a script that automatically creates markdown for a comic. Try it online here!
Teh Code and other details
import urllib.request as request
import json
print('This is "XKCD comic markdownifier for Stack Exchange."')
print('(Note that I\'m not affiliated with XKCD or Stack Exchange in anyway.)')
print('The posting of the code is at http://meta.stackexchange.com/q/263514/177681.')
print('This code will format an XKCD comic so it may be posted to Stack Exchange.')
num = input('What is the number of the comic?')
req = request.urlopen('https://xkcd.com/%s/info.0.json' % num)
str_response = req.read()
obj = json.loads(str_response)
print('[s "%(alt)s")](https://www.xkcd.com/%(num)s)' % obj)
The current format is [](comicUrl)]
.
This for example, when given 1
, outputs [.jpg "Don't we all.")](https://www.xkcd.com/1)
.
You can fork it here.
At the moment, you need to manually escape parentheses and such in the markdown. Luckily, this is usually unnecessary. Also, when run on bad input, it will through a syntax error (somehow.)
What do you guys think? Is it a good format? If you have any modifications, feel free to post it (although make sure it works as a runnable snippet. trinket.io is finky). String escaping would be nice. Error checking would also be nice.