Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ircutils import bot, start_all
- import mechanize
- import shlex
- from bs4 import BeautifulSoup
- class yapib(bot.SimpleBot):
- def __init__(self, nick):
- bot.SimpleBot.__init__(self, nick)
- self.nick = "NFO_Bot"
- self.real_name = "Based on http://github.com/Transfusion/yapib"
- self.user = "cutie"
- self["any"].add_handler(self.print_line)
- self.verbose = False
- def print_line(self, client, event):
- kwds = {
- "cmd": event.command,
- "src": event.source,
- "tgt": event.target,
- "params": event.params
- }
- print "[{cmd}] s={src!r} t={tgt!r} p={params}".format(**kwds)
- def on_channel_message(self, event):
- tx = event.message.split()
- rx = tx[0].upper()
- params = tx[1:]
- global nw1
- nw1 = []
- def nfo(srch, r1, r2):
- newlist = []
- br = mechanize.Browser()
- br.open("http://www.xrel.to/home.html")
- br.select_form(nr=0)
- br["xrel_search_query"] = srch
- res = br.submit()
- soup = BeautifulSoup(res.read())
- for link in soup.find_all('a'):
- u = link.get('href')
- if "nfo" in u and "derefer" not in u and u not in newlist:
- newlist.append(u)
- else: pass
- for item in newlist[r1:r2]:
- nw1.append(str("http://www.xrel.to"+item))
- nw1.append("result count: " + str(len(newlist)))
- nw1.append("results "+str(r1)+" to "+str(r2))
- if event.message.startswith("!nfo"):
- t = shlex.split(event.message)
- print t[1]
- print t[2]
- print t[3]
- nfo(t[1], int(t[2]), int(t[3]))
- for i in nw1:
- self.send_message(event.target, i)
- else: pass
- if __name__ == "__main__":
- instance = yapib("NFO_Bot")
- instance.connect("server.hostname.com", port=1111, channel="#blahchannel")
- start_all()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement