/xkcdxx

xkcd web-comics loader library

Primary LanguageC++MIT LicenseMIT

xkcdxx

This library could be used to bring funny xkcd web-comics to your applications.

Like this:

Exploits of a Mom

Do you remember? Live example. The work was inspired by existing Python package.

Description

There are no specific external dependencies except stuff in standards and popular OpenSSL (>= 1.1.1) library. Implemented both static and shared thread-safe variants.

Supported interfaces:

  • Plain C
  • Modern C++
  • Python-3 binding

Pre-built packages:

  • Ubuntu 18.04 LTS, amd64
  • Ubuntu 20.04 LTS, amd64

Installation guide

Ready packages are available from Canonical PPA:

$ sudo add-apt-repository --yes --update ppa:vyivanov/xkcdxx
$ sudo apt install --yes xkcdxx python3-xkcdxx

Usage examples

#include <xkcd.h>
#include <stdio.h>

xkcd_comic idx = xkcd_comic_latest();
if (idx) {
    xkcd_info info = xkcd_comic_info(idx);
    printf("%s", info.url);
    xkcd_comic_destroy(idx);
    idx = XKCD_COMIC_NULL;
} else {
    printf("%s", xkcd_comic_error());
}
#include <xkcdxx.h>
#include <iostream>

try {
    xkcdxx::Comic comic{xkcdxx::Comic::Number::Latest};
    std::cout << comic.url();
} catch (xkcdxx::Comic::RequestFailed& ex) {
    std::cout << ex.what();
}
import xkcdxx

try:
    comic = xkcdxx.Comic(xkcdxx.Comic.LATEST)
    print(comic.url())
except xkcdxx.Comic.RequestFailed as ex:
    print(ex)