#!/usr/bin/env python3

# http://inamidst.com/saxo/
# Created by Sean B. Palmer

import re
import saxo

item = re.compile("<td>([^<\n]+)|span class=([^ >]+)")

@saxo.pipe
def ssl(arg):
    arg = arg.split("//", 1).pop()
    arg = arg.split("/", 1)[0]
    page = saxo.request("http://dpk.io/ssl/" + arg)
    text = page["text"]
    if "<h2>Error" in text:
        return "Error: " + text.split("<p>", 1).pop().split("\n", 1)[0]
    items = enumerate((a or b) for (a, b) in item.findall(text))
    items = (item + ("," if (i % 2) else ":") for (i, item) in items)
    return " ".join(items).rstrip(",")
