Example #1
0
def title(who, what, where):
    res = re.search(_URL_RE, what)
    if not res:
        return
    url = res.group(0)
    try:
        req = urllib2.Request(url, headers={'User-Agent': 'Yakr'})
        content = urllib2.urlopen(req, timeout=5).read(4096)
    except urllib2.HTTPError as e:
        if e.code == 401:
            say(where, "I don't have login info for that link. No title for you! (401)")
        elif e.code == 403:
            say(where, "That website told me to GTFO (403). ROBOT HATER!")
        elif e.code == 404:
            say(where, "I don't know where you think you're sending people, but that website told me it couldn't find your link. (404)")
        elif e.code == 405:
            say(where, "I'm not supposed to be GETting that link. You're going to get me in trouble, {}! D:< ({})".format(who, e.code))
        elif e.code == 418:
            say(where, "Ooh, a teapot! Thank you for the lovely tea, {}!".format(who))
        else:
            say(where, "I ran into a sort of problem, you see. I dunno what to do! ({}) {}".format(e.code, e.reason))
        return
    except Exception as e:
        say(where, "O.o %r" % e.message )
        return
    if content.find("</title>") == -1:
        return
    title_content = content.split("</title>")[0].split(">")[-1]
    title_content = re.sub("\W+", " ", title_content) #clean up whitespace

    title = unescape(title_content)

    say(where, "<{B}Title{}: {C7}%s{}>" % title)
Example #2
0
def title(who, what, where):
    res = re.search(_URL_RE, what)
    if not res:
        return
    url = res.group(0)
    try:
        req = urllib2.Request(url, headers={'User-Agent': 'Yakr'})
        content = urllib2.urlopen(req, timeout=5).read(4096)
    except urllib2.HTTPError as e:
        if e.code == 401:
            say(
                where,
                "I don't have login info for that link. No title for you! (401)"
            )
        elif e.code == 403:
            say(where, "That website told me to GTFO (403). ROBOT HATER!")
        elif e.code == 404:
            say(
                where,
                "I don't know where you think you're sending people, but that website told me it couldn't find your link. (404)"
            )
        elif e.code == 405:
            say(
                where,
                "I'm not supposed to be GETting that link. You're going to get me in trouble, {}! D:< ({})"
                .format(who, e.code))
        elif e.code == 418:
            say(where,
                "Ooh, a teapot! Thank you for the lovely tea, {}!".format(who))
        else:
            say(
                where,
                "I ran into a sort of problem, you see. I dunno what to do! ({}) {}"
                .format(e.code, e.reason))
        return
    except Exception as e:
        say(where, "O.o %r" % e.message)
        return
    if content.find("</title>") == -1:
        return
    title_content = content.split("</title>")[0].split(">")[-1]
    title_content = re.sub("\W+", " ", title_content)  #clean up whitespace

    title = unescape(title_content)

    say(where, "<{B}Title{}: {C7}%s{}>" % title)
Example #3
0
def define(who, what, where):
    if what == "":
        say("!gd <term> [number]")
        return

    match = re.search("^(.*?)( [0-9]+|)$", what)
    term, num = match.groups()
    if not num:
        num = 0
    else:
        num = int(num) - 1
    if num < 0:
        say(where, "Definitions run from 1 to N")
        #User input is from 1 to N
        #The variable 'num' is from 0 to N-1
        return

    url = _API_URL + urllib2.quote(term)
    reply = urllib2.urlopen(url).read()
    results = []
    try:
        null = None
        db = eval(reply[24:])
        results = db[0]["webDefinitions"][0]["entries"]
    except:
        pass
    if len(results) == 0:
        say(where,
            "I have no idea what you're talking about '%s' pfft." % term)
        return

    if num >= len(results):
        say(where, "Only %s results." % len(results))
        return
    try:
        result = results[num]["terms"][0]["text"]
        definition = unescape(result)
        say(
            where, "<{C3}Google Define{}: %s [{B}%s{} of %s]>" %
            (definition, num + 1, len(results)))
    except:
        import traceback
        traceback.print_exc()
Example #4
0
def define(who, what, where):
    if what == "":
        say("!gd <term> [number]")
        return

    match = re.search("^(.*?)( [0-9]+|)$", what)
    term, num = match.groups()
    if not num:
        num = 0
    else:
        num = int(num)-1
    if num < 0:
        say(where, "Definitions run from 1 to N")
        #User input is from 1 to N
        #The variable 'num' is from 0 to N-1
        return
    
    url = _API_URL + urllib2.quote(term)
    reply = urllib2.urlopen(url).read()
    results = []
    try:
        null = None
        db = eval(reply[24:])
        results = db[0]["webDefinitions"][0]["entries"]
    except:
        pass
    if len(results) == 0:
        say(where, "I have no idea what you're talking about '%s' pfft." % term)
        return

    if num >= len(results):
        say(where, "Only %s results." % len(results))
        return
    try:
        result = results[num]["terms"][0]["text"]
        definition = unescape(result)
        say(where,
            "<{C3}Google Define{}: %s [{B}%s{} of %s]>" % (
            definition, num + 1, len(results)
        ))
    except:
        import traceback; traceback.print_exc()
Example #5
0
def title(who, what, where):
    res = re.search(_URL_RE, what)
    if not res:
        return
    url = res.group(0)
    try:
        content = urllib2.urlopen(url, None, 5).read(4096)
    except urllib2.HTTPError:
        say(where, "Aww that website hates robots! ROBOT HATER!")
        return
    except Exception as e:
        say(where, "O.o %r" % e.message)
    if content.find("</title>") == -1:
        return
    title_content = content.split("</title>")[0].split(">")[-1]
    title_content = re.sub("\W+", " ", title_content)  #clean up whitespace

    title = unescape(title_content)

    say(where, "<{B}Title{}: {C7}%s{}>" % title)
Example #6
0
def title(who, what, where):
    res = re.search(_URL_RE, what)
    if not res:
        return
    url = res.group(0)
    try:
        content = urllib2.urlopen(url, None, 5).read(4096)
    except urllib2.HTTPError:
        say(where, "Aww that website hates robots! ROBOT HATER!")
        return
    except Exception as e:
        say(where, "O.o %r" % e.message )
    if content.find("</title>") == -1:
        return
    title_content = content.split("</title>")[0].split(">")[-1]
    title_content = re.sub("\W+", " ", title_content) #clean up whitespace

    title = unescape(title_content)

    say(where, "<{B}Title{}: {C7}%s{}>" % title)