Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def wikipedia_search(query):
- query = query.replace('!', '')
- query = web.quote(query)
- uri = 'https://en.wikipedia.org/w/api.php?action=query&list=search&continue=&srsearch=%s&format=json' % query
- bytes = web.get(uri)
- jsonstring = json.loads(bytes)
- whits = jsonstring['query']['searchinfo']['totalhits']
- if whits > 0:
- wtitle = jsonstring['query']['search'][0]['title']
- wwords = str(jsonstring['query']['search'][0]['wordcount'])
- wsearch = wtitle.replace('!', '')
- wsearch = web.quote(wsearch)
- base_url = "https://en.wikipedia.org/wiki/"+wsearch
- return (wtitle + " - " + wwords + " words " + base_url)
- def wikipedia(phenny, input):
- """Queries Wikipedia for the specified input."""
- query = input.group(2)
- if not query: return phenny.reply('.w what?')
- uri = wikipedia_search(query)
- if uri:
- phenny.say("Here's what I got, " + input.nick + ": " + uri)
- if not hasattr(phenny.bot, 'last_seen_uri'):
- phenny.bot.last_seen_uri = {}
- phenny.bot.last_seen_uri[input.sender] = uri
- else: phenny.say("Sorry " + input.nick + ", I couldn't find anything for '%s'." % query)
- wikipedia.commands = ['w', 'wikipedia']
- wikipedia.example = '.w swhack'
Advertisement
Add Comment
Please, Sign In to add comment