added random-quote to the wikiqoute module

master
Stefan Krulj 14 years ago
parent dee01dc1df
commit 5c4153bc3e
  1. 12
      modules/active/get_quote.py

@ -74,17 +74,21 @@ def search_wiki(code,term):
return results return results
def quote(msg,args): def quote(msg,args):
if len(args)!=3: if len(args)!=2:
brathuhn.sendMsg(brathuhn.ROOM,"Usage: "+args[0]+" language (two letter code) topic",'groupchat') brathuhn.sendMsg(brathuhn.ROOM,"Usage: "+args[0]+" language (two letter code) [topic]",'groupchat')
else: else:
try: try:
if args==2:
brathuhn.sendMsg(brathuhn.ROOM,'fetching random page...','groupchat')
url = "http://"+args[1][0:2]+".wikiquote.org/wiki/Special:Random"
else:
brathuhn.sendMsg(brathuhn.ROOM,'searching for "'+ args[2] +'"...','groupchat') brathuhn.sendMsg(brathuhn.ROOM,'searching for "'+ args[2] +'"...','groupchat')
search_results = search_wiki(args[1],args[2]) search_results = search_wiki(args[1],args[2])
if len( search_results )==0: if len( search_results )==0:
brathuhn.sendMsg(brathuhn.ROOM,"No quotes found",'groupchat') brathuhn.sendMsg(brathuhn.ROOM,"No quotes found",'groupchat')
url = "http://"+args[1][0:2]+".wikiquote.org/wiki/" + urllib2.quote(search_results[0])
url = "http://"+args[1][0:2]+".wikiquote.org/wiki/" + urllib2.quote(search_results[0])
req = urllib2.Request(url, headers={'User-Agent' : "Magic Browser"}) req = urllib2.Request(url, headers={'User-Agent' : "Magic Browser"})
con = urllib2.urlopen( req ) con = urllib2.urlopen( req )
@ -104,4 +108,4 @@ def quote(msg,args):
except exceptions.Exception as e: except exceptions.Exception as e:
brathuhn.sendMsg(brathuhn.ROOM,"Network Error "+unicode(e),'groupchat') brathuhn.sendMsg(brathuhn.ROOM,"Network Error "+unicode(e),'groupchat')
brathuhn.addCommand("quote","Usage: !quote language (two letter code) topic",quote) brathuhn.addCommand("quote","Usage: !quote language (two letter code) [topic]",quote)

Loading…
Cancel
Save