Advertisement
Guest User

Simple AU Bot

a guest
Oct 8th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #!/usr/bin/python
  2. #
  3. # IRC b0t that keeps track of RSS feeds
  4. #
  5. # Licensed under the GNU General Public License v3
  6. #
  7. # Copyright (2009) by Akarsh Simha
  8. # Fork by (2012) Amith kk
  9.  
  10. import irclib
  11. import feedparser
  12. import os
  13. import threading
  14. import time
  15.  
  16. channel_list = [ "#2buntu" ] # Put in a list of channels
  17. feed_list = [ "http://askubuntu.com/feeds/tag?tagnames=12.04&sort=newest"]
  18. old_entries_file = os.environ.get("HOME") + "/.b0t/old-feed-entries"
  19.  
  20. irc = irclib.IRC()
  21. server = irc.server()
  22.  
  23. server.connect( "irc.freenode.org", 6667, "j0seph_" ) # TODO: Make this general
  24. # server.privmsg( "NickServ", "identify " )
  25.  
  26. msgqueue = []
  27.  
  28. def feed_refresh():
  29. #print "Test"
  30. FILE = open( old_entries_file, "r" )
  31. filetext = FILE.read()
  32. FILE.close()
  33. for feed in feed_list:
  34. NextFeed = False
  35. d = feedparser.parse( feed )
  36. for entry in d.entries:
  37. id = entry.link.encode('utf-8')+entry.title.encode('utf-8')
  38. if id in filetext:
  39. NextFeed = True
  40. else:
  41. FILE = open( old_entries_file, "a" )
  42. #print entry.title + "\n"
  43. FILE.write( id + "\n" )
  44. FILE.close()
  45. msgqueue.append( entry.title.encode('utf-8') + " : " + entry.link.encode('utf-8') )
  46. if NextFeed:
  47. break;
  48.  
  49. t = threading.Timer( 900.0, feed_refresh ) # TODO: make this static
  50. t.start()
  51.  
  52. for channel in channel_list:
  53. server.join( channel )
  54.  
  55. feed_refresh()
  56.  
  57. while 1:
  58. while len(msgqueue) > 0:
  59. msg = msgqueue.pop()
  60. for channel in channel_list:
  61. server.privmsg( channel, msg )
  62. time.sleep(1) # TODO: Fix bad code
  63. irc.process_once()
  64. time.sleep(1) # So that we don't hog the CPU!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement