askcompu

Untitled

Jul 22nd, 2015
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. def wikipedia_search(query):
  2.     query = query.replace('!', '')
  3.     query = web.quote(query)
  4.     uri = 'https://en.wikipedia.org/w/api.php?action=query&list=search&continue=&srsearch=%s&format=json' % query
  5.     base_url = "https://en.wikipedia.org/wiki/"+query
  6.     bytes = web.get(uri)
  7.     m = r_wikipedia.search(bytes)
  8.     if m: return web.decode(m.group(1))
  9.  
  10. def wikipedia(phenny, input):
  11.     query = input.group(2)
  12.     if not query: return phenny.reply('.w what?')
  13.  
  14.     uri = wikipedia_search(query)
  15.     if uri:
  16.         phenny.reply(uri)
  17.         if not hasattr(phenny.bot, 'last_seen_uri'):
  18.             phenny.bot.last_seen_uri = {}
  19.         phenny.bot.last_seen_uri[input.sender] = uri
  20.     else: phenny.reply("No results found for '%s'." % query)
  21. wikipedia.commands = ['wikipedia', 'w']
Advertisement
Add Comment
Please, Sign In to add comment