Beispiel #1
0
def wcsolve(connection, channel, nick, cmd, args):
    #"""Usage: revsolve (chall nr | chall name) [user]"""
    """Shows how many solved a challenge. Usage: wcsolve (chall nr | chall name)"""
    print "wcsolve", args
    if time.time() - cache_ts > 1 * 60:
        print "time diff", (time.time() - cache_ts)
        build_cache()

    if not args:
        plugins.print_help(connection, channel, nick, None, cmd)
        return

    nr, name, url, solvers = None, None, None, None
    if args.isdigit():
        nr = args
        if nr_to_url.has_key(nr):
            name, url, solvers = nr_to_url[nr]
    else:
        for key, val in nr_to_url.items():
            if val[0].lower().startswith(args.lower()):
                nr = key
                name, url, solvers = val
                break
            if args.lower() in val[0].lower():
                nr = key
                name, url, solvers = val

    txt = "No such challenge."
    if solvers is not None:
        txt = "Challenge Nr. %s, %s, has been solved by %d user%s." % (nr, name, solvers, "" if solvers == 1 else "s")

    plugins.say(connection, channel, txt)
Beispiel #2
0
def movie(connection, channel, nick, cmd, args):
    """Shows information about movie from themoviedb.org"""
    if not args or not args.strip():
        return plugins.print_help(connection, channel, nick, None, cmd)

    args = args.strip()
    id = -1
    res = tmdb.Search().movie(query=args)
    if res["total_results"] > 0:
        id = res["results"][0]["id"]

    if id < 0:
        return plugins.say(connection, channel, "No such movie.")

    movie = tmdb.Movies(id)
    movie_info = movie.info()
    txt = "\x02%s\x02" % movie_info["title"]
    if movie_info["title"] != movie_info["original_title"]:
        txt += " (%s)" % movie_info["original_title"]
    if movie_info["release_date"]:
        txt += " | \x02Released:\x02 %s" % movie_info["release_date"]
    if movie_info["vote_count"] > 0:
        txt += " | \x02Rating:\x02 %.1f/10" % movie_info["vote_average"]
    if movie_info["homepage"]:
        txt += " | \x02Homepage:\x02 %s" % movie_info["homepage"]

    plugins.say(connection, channel, txt)
    plugins.say(connection, channel, plugins.split(movie_info["overview"]))
Beispiel #3
0
def tv(connection, channel, nick, cmd, args):
    """Shows information about tv series from themoviedb.org"""
    if not args or not args.strip():
        return plugins.print_help(nick, channel, None, cmd)

    args = args.strip()
    id = -1
    res = tmdb.Search().tv(query=args)
    if res["total_results"] > 0:
        id = res["results"][0]["id"]

    if id < 0:
        return plugins.say(connection, channel, "No such tv series.")

    movie = tmdb.TV(id)
    movie_info = movie.info()
    txt = "\x02%s\x02" % movie_info["name"]
    if movie_info["name"] != movie_info["original_name"]:
        txt += " (%s)" % movie_info["original_name"]
    if movie_info["first_air_date"]:
        txt += " | \x02First Aired:\x02 %s" % movie_info["first_air_date"]
    if movie_info["number_of_seasons"]:
        txt += " | \x02Nr. of Seasons:\x02 %d" % movie_info["number_of_seasons"]
    if movie_info["vote_count"] > 0:
        txt += " | \x02Rating:\x02 %.1f/10" % movie_info["vote_average"]
    if movie_info["homepage"]:
        txt += " | \x02Homepage:\x02 %s" % movie_info["homepage"]

    plugins.say(connection, channel, txt)
    plugins.say(connection, channel, plugins.split(movie_info["overview"]))
Beispiel #4
0
def vs(connection, channel, nick, cmd, args):
    """Usage: vs "search term 1" "search term 2" -- Compares the number of google results for both terms."""
    if not args:
        return plugins.print_help(connection, channel, nick, None, cmd)

    try:
        v = shlex.split(args)
    except Exception as e:
        return plugins.say(connection, channel, str(e))
    
    if len(v) != 2:
        return plugins.print_help(connection, channel, nick, None, cmd)
    
    term1, term2 = v
    hits1 = google_search(term1.encode("utf-8"))[0]
    hits2 = google_search(term2.encode("utf-8"))[0]
    h1 = locale.format("%d", hits1, 1)
    h2 = locale.format("%d", hits2, 1)
    plugins.say(connection, channel, "%s %s %s %s %s" % (term1, h1, create_bar(hits1, hits2, 21), h2, term2))
Beispiel #5
0
def helper(connection, channel, nick, cmd, args, what):
    if not args:
        return plugins.print_help(connection, channel, nick, None, cmd)

    count, hits, searchurl = google_search(args, what)
    for h in hits:
        plugins.say(connection, channel, "%s | %s" % (html.unescape(h["titleNoFormatting"]), h["unescapedUrl"]))
    if hits:
        plugins.say(connection, channel, "For more results, see %s (%s hits)" % (searchurl, locale.format("%d", count, 1)))
    else:
        plugins.say(connection, channel, "Found no results. See for yourself: %s" % searchurl)
Beispiel #6
0
def wtf(connection, channel, nick, cmd, args):
    index = 0
    try:
        pargs = parser.parse_args(shlex.split(args or ""))
        if parser.help_requested:
            return plugins.say(connection, channel, parser.format_help().strip())
        if pargs.nr:
            index = int(pargs.nr) - 1
    except plugins.ArgumentParserError as e:
        return plugins.say(connection, channel, "error: %s" % str(e))
    except (SystemExit, NameError, ValueError):
        return plugins.print_help(connection, channel, nick, None, cmd)
    
    page = index / 7 + 1
    index %= 7
    term = pargs.search_term

    """
    if term.lower() == "maddinw":
        return plugins.say(channel, "A guy commonly referred to as Strong Mad.")
    elif term.lower() == "dloser":
        return plugins.say(channel, "<Jhype> dloser: a thoughtful friend ")
    """

    tree = lxml.html.parse("http://www.urbandictionary.com/define.php?term=%s&page=%d" % (urllib.quote_plus(term.encode("utf-8")), page))
    entries = tree.xpath("//div[@class='def-panel' and @data-defid]")
    if not entries:
        return plugins.say(connection, channel, "'%s' has no definition at http://www.urbandictionary.com" % term)

    if index >= len(entries) or index < 0:
        return plugins.say(connection, channel, "No definition nr %d available" % (index + 1))

    count = "?"
    count_div = tree.xpath("//div[contains(@class, 'definition-count-panel')]")
    if count_div:
        try:
            count = str(1 + int(count_div[0].text_content().split()[0]))
        except Exception as e:
            print e
            pass

    txt = "\x02[Definition %d/%s]\x0f " % (index + 1, count)
    definition = extract_text(entries[index], ".//div[@class='meaning']")
    if len(definition) > 300:
        definition = definition[:300] + "..."
    txt += definition
    
    example = extract_text(entries[index], ".//div[@class='example']")
    if example:
        if len(example) > 300:
            example = example[:300] + "..."
        txt += "\n\x02Example:\x0f " + example

    plugins.say(connection, channel, txt)
Beispiel #7
0
def tbssolve(connection, channel, nick, cmd, args):
    #"""Usage: tbssolve chall_name"""
    """Shows how many solved a challenge. Usage: tbssolve chall_name"""

    if not args:
        plugins.print_help(connection, channel, nick, None, cmd)
        return

    build_cache()
    print solved_cache
    name, url, solved = None, None, None
    for n, u, s in solved_cache:
        if n.lower().startswith(args.lower()):
            name = n
            url = u
            solved = s
            break

    txt = "No such challenge."
    if name:
        txt = "Challenge '%s' has been solved by %d user%s." % (name, solved, "" if solved == 1 else "s")

    plugins.say(connection, channel, txt)
Beispiel #8
0
def yt_search(connection, channel, nick, cmd, args):
    if not args:
        return plugins.print_help(connection, channel, nick, None, cmd)