Guest User

Untitled

a guest
Apr 11th, 2014
31
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import ch
  3. import random
  4. import time, threading
  5. import urllib
  6. import urllib2
  7. import sys
  8. from xml.dom import minidom
  9. from xml.dom.minidom import parseString
  10. import os
  11.  
  12. class TestBot(ch.RoomManager):
  13.  
  14.     def checkPosts(self, room):
  15.         hdr = {'User-Agent': 'Mozilla/5.0'}
  16.         req = urllib2.Request("http://bakaforum.info/syndication.php?type=atom1.0",headers=hdr)
  17.         page = urllib2.urlopen(req)
  18.         content = page.read()
  19.         dom = parseString(content)
  20.  
  21.         xmlTag = dom.getElementsByTagName('title')[1].toxml()
  22.         xmlData=xmlTag.replace('<title>','').replace('</title>','')
  23.         xmlDatafinal=xmlData.replace('<title type="html" xml:space="preserve"><![CDATA[','').replace(']]>','').encode('utf-8')
  24.  
  25.         f=open("lastpost.txt",'r+')
  26.         x=f.read().decode('utf-8')
  27.         if(xmlDatafinal==x):
  28.             print "igual"
  29.             f.close()
  30.         else:
  31.             print "guardado e postado"
  32.             xmlTag2 = dom.getElementsByTagName('id')[1].toxml()
  33.             xmlData2=xmlTag2.replace('<id>','').replace('</id>','')
  34.             room.message(" topico postado: "+xmlData2)
  35.             f.seek(0)
  36.             f.truncate()
  37.             f.write(str(xmlDatafinal))
  38.             f.close()
  39.  
  40.     def onConnect(self, room):
  41.         self.setInterval(2, self.checkPosts, room)
  42.  
  43. if __name__ == "__main__":
  44.     TestBot.easy_start( rooms=['ugtforumanime'], name='teste300194', password='fe300194' )
RAW Paste Data