Beispiel #1
0
def title(inp, db=None, chan=None):
    ".title <url> - get title of <url>"
    if inp == '^':
        urlhistory.db_init(db)
        rows = db.execute(
            "select url from urlhistory where chan = ? order by time desc limit 1",
            (chan, ))
        if not rows.rowcount:
            return "No url in history."

        inp = rows.fetchone()[0]

    try:
        parts = urlparse.urlsplit(inp)
        conn = httplib.HTTPConnection(parts.hostname, timeout=10)
        path = parts.path

        if parts.query:
            path += "?" + parts.query

        conn.request('HEAD', path)
        resp = conn.getresponse()

        if not (200 <= resp.status < 400):
            return "Error: HEAD %s %s" % (resp.status, resp.reason)

        errors = check_response(dict(resp.getheaders()))

        if errors:
            return errors
    except Exception as e:
        return "Error: " + str(e)

    try:
        req = urllib2.urlopen(inp)
    except Exception as e:
        return "Error: GET %s" % e

    errors = check_response(req.headers)

    if errors:
        return errors

    text = req.read(maxlen).decode('utf8', 'ignore')

    match = titler.search(text)

    if not match:
        return "Error: no title"

    rawtitle = match.group(1)

    title = repaste.decode_html(rawtitle)
    title = " ".join(title.split())

    return title
Beispiel #2
0
def title(inp, db=None, chan=None):
    ".title <url> - get title of <url>"
    if inp == '^':
        urlhistory.db_init(db)
        rows = db.execute("select url from urlhistory where chan = ? order by time desc limit 1", (chan,))
        if not rows.rowcount:
            return "No url in history. " + randout.fail()

        inp = rows.fetchone()[0]

    try:
        parts = urlparse.urlsplit(inp)
        conn = httplib.HTTPConnection(parts.hostname, timeout=10)
        path = parts.path

        if parts.query:
            path += "?" + parts.query

        conn.request('HEAD', path)
        resp = conn.getresponse()

        if not (200 <= resp.status < 400):
            return "Error: HEAD %s %s " + randout.fail() % (resp.status, resp.reason)

        errors = check_response(dict(resp.getheaders()))

        if errors:
            return errors
    except Exception as e:
        return "Error: " + str(e)

    try:
        req = urllib2.urlopen(inp)
    except Exception as e:
        return "Error: GET %s " + randout.fail() % e

    errors = check_response(req.headers)

    if errors:
        return errors

    text = req.read(maxlen).decode('utf8', 'ignore')

    match = titler.search(text)

    if not match:
        return "Error: no title " + randout.fail()

    rawtitle = match.group(1)

    title = repaste.decode_html(rawtitle)
    title = " ".join(title.split())

    return title
Beispiel #3
0
def title(inp, db=None, chan=None):
    ".title <url> - get title of <url>"
    if inp == '^':
        urlhistory.db_init(db)
        rows = db.execute("select url from urlhistory where chan = ? order by time desc limit 1", (chan,))
        if not rows.rowcount:
            return "No url in history."

        inp = rows.fetchone()[0]

    match = titler.search(http.get(inp))

    if not match:
        return "Error: no title"

    rawtitle = match.group(1)

    title = repaste.decode_html(rawtitle)
    title = " ".join(title.split())

    return title
Beispiel #4
0
def title(inp, db=None, chan=None):
    ".title <url> - get title of <url>"
    if inp == '^':
        urlhistory.db_init(db)
        rows = db.execute(
            "select url from urlhistory where chan = ? order by time desc limit 1",
            (chan, ))
        if not rows.rowcount:
            return "No url in history."

        inp = rows.fetchone()[0]

    match = titler.search(http.get(inp))

    if not match:
        return "Error: no title"

    rawtitle = match.group(1)

    title = repaste.decode_html(rawtitle)
    title = " ".join(title.split())

    return title