Advertisement
Transfusion

xrel.to IRC NFO Bot - Beta

Apr 1st, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. from ircutils import bot, start_all
  2. import mechanize
  3. import shlex
  4. from bs4 import BeautifulSoup
  5.  
  6. class yapib(bot.SimpleBot):
  7. def __init__(self, nick):
  8. bot.SimpleBot.__init__(self, nick)
  9. self.nick = "NFO_Bot"
  10. self.real_name = "Based on http://github.com/Transfusion/yapib"
  11. self.user = "cutie"
  12. self["any"].add_handler(self.print_line)
  13. self.verbose = False
  14.  
  15. def print_line(self, client, event):
  16. kwds = {
  17. "cmd": event.command,
  18. "src": event.source,
  19. "tgt": event.target,
  20. "params": event.params
  21. }
  22. print "[{cmd}] s={src!r} t={tgt!r} p={params}".format(**kwds)
  23. def on_channel_message(self, event):
  24. tx = event.message.split()
  25. rx = tx[0].upper()
  26. params = tx[1:]
  27.  
  28. global nw1
  29. nw1 = []
  30. def nfo(srch, r1, r2):
  31. newlist = []
  32. br = mechanize.Browser()
  33. br.open("http://www.xrel.to/home.html")
  34. br.select_form(nr=0)
  35. br["xrel_search_query"] = srch
  36. res = br.submit()
  37. soup = BeautifulSoup(res.read())
  38. for link in soup.find_all('a'):
  39. u = link.get('href')
  40. if "nfo" in u and "derefer" not in u and u not in newlist:
  41. newlist.append(u)
  42. else: pass
  43. for item in newlist[r1:r2]:
  44. nw1.append(str("http://www.xrel.to"+item))
  45. nw1.append("result count: " + str(len(newlist)))
  46. nw1.append("results "+str(r1)+" to "+str(r2))
  47.  
  48. if event.message.startswith("!nfo"):
  49. t = shlex.split(event.message)
  50. print t[1]
  51. print t[2]
  52. print t[3]
  53. nfo(t[1], int(t[2]), int(t[3]))
  54. for i in nw1:
  55. self.send_message(event.target, i)
  56. else: pass
  57.  
  58.  
  59.  
  60. if __name__ == "__main__":
  61. instance = yapib("NFO_Bot")
  62. instance.connect("server.hostname.com", port=1111, channel="#blahchannel")
  63.  
  64. start_all()
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement