Commits

Benoit C  committed 6bb6916

changes in configuration. makes async module stop cleanly

  • Participants
  • Parent commits a735756

Comments (0)

Files changed (4)

File autiste/core.py

                 print e
         print self.modules
 
+
+    def unload_modules(self):
+        for modname, module in self.modules.items():
+            if isinstance(module, AsyncModule):
+                module.stop()
+            del self.modules[modname]
+
     @module_call
     def connectionMade(self):
         irc.IRCClient.connectionMade(self)
     @module_call
     def connectionLost(self, reason):
         irc.IRCClient.connectionLost(self, reason)
+        self.unload_modules()
 
     # callbacks for events
     def userJoined(self, user, channel):

File autiste/modules/base.py

         IrcModule.__init__(self, conf, irc)
         threading.Thread.__init__(self)
 
+    def stop(self):
+        raise NotImplementedError

File autiste/modules/twitter.py

 import twitter
 import pycurl
 import simplejson as json
-
+import thread
 from base import AsyncModule
 
 STREAM_URL="http://stream.twitter.com/1/statuses/filter.json"
         self.pyc.setopt(pycurl.USERPWD, "%s:%s" % (self.conf.get("user"), self.conf.get("pass")))
         self.pyc.setopt(pycurl.URL, STREAM_URL)
         self.pyc.setopt(pycurl.WRITEFUNCTION, self.on_receive)
-        self.pyc.setopt(pycurl.POSTFIELDS, "follow=24299195,116523453,15687408,38331159")
+        self.pyc.setopt(pycurl.POSTFIELDS, "follow=24299195,116523453,15687408,15180881")
         self.pyc.setopt(pycurl.POST, 1)
-        self.pyc.setopt(pycurl.VERBOSE, 1)
         self.pyc.perform()
 
 
+    def stop(self):
+        self.pyc.reset()
+        del self.pyc
+
     def on_receive(self, data):
-        print "on_receive", data
         self.buffer += data
         if data.endswith("\r\n") and self.buffer.strip():
             content = json.loads(self.buffer)
             self.buffer = ""
+            text = content.get('text')
+            if text.startswith("RT") or text.startswith("@"):
+                return
             if "text" in content:
-                self.irc.say("#dzen", asciize(u"{0[user][name]}: {0[text]}".format(content)))
-                print "{0[user][name]}: {0[text]}".format(content)
+                self.irc.say("#dzen", asciize(u"@{0[user][screen_name]}: {0[text]}".format(content)))
 
     def name(self):
         return 'TwitterFeed'
         logdir: log
         logsuffix: .log
         channels: [autism]
+modules:
+    twitter:
+        user: username
+        pass: password
+        follow: [24299195,116523453,15687408]
+    links: None
+    logger:
+        logdir: log
+        logsuffix: .log
+