# Path: cardinal/decorators.py
# def command(triggers):
#     if isinstance(triggers, str):
#         triggers = [triggers]
# 
#     if not isinstance(triggers, list):
#         raise TypeError("Command must be a trigger string or list of triggers")
# 
#     def wrap(f):
#         f.commands = triggers
#         return f
# 
#     return wrap
# 
# Path: cardinal/decorators.py
# def help(lines):
#     # For backwards compatibility
#     if isinstance(lines, str):
#         lines = [lines]
# 
#     if not isinstance(lines, list):
#         raise TypeError("Help must be a help string or list of help strings")
# 
#     def wrap(f):
#         # Create help list or prepend to it
#         if not hasattr(f, 'help'):
#             f.help = lines
#         else:
#             f.help = lines + f.help
# 
#         return f
# 
#     return wrap


from datetime import datetime
from twisted.internet import defer
from twisted.internet.threads import deferToThread
from cardinal.decorators import command
from cardinal.decorators import help
import logging
import requests




class ShowNotFoundException(Exception):
    pass


@defer.inlineCallbacks
def fetch_show(show):
    r = yield deferToThread(
        requests.get,
        "https://api.tvmaze.com/singlesearch/shows",
        params={"q": show}
    )

    if r.status_code == 404:
        raise ShowNotFoundException
    r.raise_for_status()

    data = r.json()

    network = None
    if data['network']:
        network = data['network']['name']
        country = data['network']['country']
        if country:
            country = country['code']
    elif data['webChannel']:

# Path: cardinal/decorators.py
# def command(triggers):
#     if isinstance(triggers, str):
#         triggers = [triggers]
# 
#     if not isinstance(triggers, list):
#         raise TypeError("Command must be a trigger string or list of triggers")
# 
#     def wrap(f):
#         f.commands = triggers
#         return f
# 
#     return wrap
# 
# Path: cardinal/decorators.py
# def help(lines):
#     # For backwards compatibility
#     if isinstance(lines, str):
#         lines = [lines]
# 
#     if not isinstance(lines, list):
#         raise TypeError("Help must be a help string or list of help strings")
# 
#     def wrap(f):
#         # Create help list or prepend to it
#         if not hasattr(f, 'help'):
#             f.help = lines
#         else:
#             f.help = lines + f.help
# 
#         return f
# 
#     return wrap


# Path: plugins/tv/plugin.py
from datetime import datetime
from twisted.internet import defer
from twisted.internet.threads import deferToThread
from cardinal.decorators import command
from cardinal.decorators import help
import logging
import requests





class ShowNotFoundException(Exception):
    pass


@defer.inlineCallbacks
def fetch_show(show):
    r = yield deferToThread(
        requests.get,
        "https://api.tvmaze.com/singlesearch/shows",
        params={"q": show}
    )

    if r.status_code == 404:
        raise ShowNotFoundException
    r.raise_for_status()

    data = r.json()

    network = None
    if data['network']:
        network = data['network']['name']
        country = data['network']['country']
        if country:
            country = country['code']
    elif data['webChannel']:

        network = data['webChannel']['name']