Created
February 28, 2016 03:35
-
-
Save kyhau/ca1e8bae52a0c35b1317 to your computer and use it in GitHub Desktop.
Random xkcd image url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
xkcd | |
""" | |
import xkcd | |
def random_xkcd(logger): | |
""" | |
Retrieve url of a random xkcd | |
""" | |
logger.debug('Running random_xkcd ...') | |
try: | |
comic = xkcd.getRandomComic() | |
return '{}:\n{}\n{}'.format( | |
comic.getAsciiTitle(), | |
comic.getAsciiAltText(), | |
comic.getAsciiImageLink() | |
) | |
except Exception as e: | |
logger.error(e) | |
return None | |
if __name__ == "__main__": | |
# debug-only | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
logger = logging.getLogger(__name__) | |
random_xkcd(logger) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment