コード例 #1
0
def google(query):
    url = google_search(query + sites_query)
    if not url:
        return None
    match = re.match('(?:https?://)?xkcd.com/(\d+)/?', url)
    if match:
        return match.group(1)
コード例 #2
0
ファイル: handmade_faq.py プロジェクト: Chronister/hmh_bot
def google(query):
    """Wraps the google search performed by the msdn command (borrowed from the xkcd command).
        Note: might not be necessary, unless other commands start using google as well. Consider
        merging into msdnSearch.
    """
    url = google_search(query + sites_query)
    return url
コード例 #3
0
def google(query):
    """Wraps the google search performed by the msdn command (borrowed from the xkcd command).
        Note: might not be necessary, unless other commands start using google as well. Consider
        merging into msdnSearch.
    """
    url = google_search(query + sites_query)
    return url
コード例 #4
0
def google(query):
    try:
        query = query.encode('utf-8')
    except:
        pass
    url = google_search(query + sites_query)
    match = re.match('(?:https?://)?xkcd.com/(\d+)/?', url)
    if match:
        return match.group(1)
コード例 #5
0
ファイル: handmade_faq.py プロジェクト: Chronister/hmh_bot
def googleSearch(bot,trigger):
    """Command that searches google for the string provided
    """
    if not trigger: return
    if stream.isCurrentlyStreaming() and not trigger.admin: return
    if not trigger.group(2):
        bot.say("@%s: https://google.com/" % trigger.nick)
    else:
        query = trigger.group(2).strip()
        bot.say("@%s: %s" % (trigger.nick, google_search(query)))
コード例 #6
0
def googleSearch(bot, trigger):
    """Command that searches google for the string provided
    """
    if not trigger: return
    if stream.isCurrentlyStreaming() and not trigger.admin: return
    if not trigger.group(2):
        bot.say("@%s: https://google.com/" % trigger.nick)
    else:
        query = trigger.group(2).strip()
        bot.say("@%s: %s" % (trigger.nick, google_search(query)))
コード例 #7
0
def xkcd(willie, trigger):
    """
    .xkcd - Finds an xkcd comic strip. Takes one of 3 inputs:
    If no input is provided it will return a random comic
    If numeric input is provided it will return that comic
    If non-numeric input is provided it will return the first google result for those keywords on the xkcd.com site
    """
    # get latest comic for rand function and numeric input
    body = urllib2.urlopen("http://xkcd.com/rss.xml").readlines()[1]
    parsed = etree.fromstring(body)
    newest = etree.tostring(parsed.findall("channel/item/link")[0])
    max_int = int(newest.split("/")[-3])

    # if no input is given (pre - lior's edits code)
    if not trigger.group(2):  # get rand comic
        random.seed()
        website = "http://xkcd.com/%d/" % random.randint(0, max_int + 1)
    else:
        query = trigger.group(2).strip()

        # numeric input! get that comic number if it exists
        if (query.isdigit()):
            if (int(query) > max_int):
                willie.say("Sorry, comic #" + query +
                           " hasn't been posted yet. The last comic was #%d" %
                           max_int)
                return
            else:
                website = "http://xkcd.com/" + query

        # non-numeric input! code lifted from search.g
        else:
            if (query.lower() == "latest"
                    or query.lower() == "newest"):  # special commands
                website = "https://xkcd.com/"
            else:  # just google
                try:
                    query = query.encode('utf-8')
                except:
                    pass
                website = google_search("site:xkcd.com " + query)
                chkForum = re.match(
                    re.compile(r'.*?([0-9].*?):.*'), find_title(
                        website))  # regex for comic specific forum threads
                if (chkForum):
                    website = "http://xkcd.com/" + chkForum.groups()[0].lstrip(
                        '0')
    if website:  # format and say result
        website += ' [' + find_title(website)[6:] + ']'
        willie.say(website)
    elif website is False:
        willie.say("Problem getting data from Google.")
    else:
        willie.say("No results found for '%s'." % query)
コード例 #8
0
ファイル: xkcd.py プロジェクト: DePierre/willie
def xkcd(bot, trigger):
    """
    .xkcd - Finds an xkcd comic strip. Takes one of 3 inputs:
    If no input is provided it will return a random comic
    If numeric input is provided it will return that comic
    If non-numeric input is provided it will return the first google result for those keywords on the xkcd.com site
    """
    # get latest comic for rand function and numeric input
    body = urllib2.urlopen("http://xkcd.com/rss.xml").readlines()[1]
    parsed = etree.fromstring(body)
    newest = etree.tostring(parsed.findall("channel/item/link")[0])
    max_int = int(newest.split("/")[-3])

    # if no input is given (pre - lior's edits code)
    if not trigger.group(2):  # get rand comic
        random.seed()
        website = "http://xkcd.com/%d/" % random.randint(0, max_int + 1)
    else:
        query = trigger.group(2).strip()

        # numeric input! get that comic number if it exists
        if (query.isdigit()):
            if (int(query) > max_int):
                bot.say("Sorry, comic #" + query + " hasn't been posted yet. The last comic was #%d" % max_int)
                return
            else:
                website = "http://xkcd.com/" + query

        # non-numeric input! code lifted from search.g
        else:
            if (query.lower() == "latest" or query.lower() == "newest"):  # special commands
                website = "https://xkcd.com/"
            else:  # just google
                try:
                    query = query.encode('utf-8')
                except:
                    pass
                website = google_search("site:xkcd.com " + query)
                chkForum = re.match(re.compile(r'.*?([0-9].*?):.*'), find_title(website))  # regex for comic specific forum threads
                if (chkForum):
                    website = "http://xkcd.com/" + chkForum.groups()[0].lstrip('0')
    if website:  # format and say result
        website += ' [' + find_title(website)[6:] + ']'
        bot.say(website)
    elif website is False:
        bot.say("Problem getting data from Google.")
    else:
        bot.say("No results found for '%s'." % query)