#!/usr/bin/env python3

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

import re
import saxo

@saxo.command()
def wow(arg):
    zone = "us"
    if arg.startswith(":") and (" " in arg):
       zone, arg = arg.split(" ", 1)
       zone = zone[1:].lower()
    server = arg.title()
    text = saxo.request("http://%s.battle.net/wow/en/status" % zone)["text"]
    status = re.compile(r'(?ims)data-tooltip="(Up|Down)">[^-]*?%s' % server)
    if "undergoing maintenance" in text:
        return "%s-%s is Down!" % (zone.upper(), server)
    for result in status.findall(text):
        return "%s-%s is %s!" % (zone.upper(), server, result)
    return "Sorry, no data available on %s-%s!" % (zone.upper(), server)
