Created
August 2, 2012 09:24
-
-
Save non117/3235754 to your computer and use it in GitHub Desktop.
Boxnya plugin. mongodbと連携してTLのdeletedを通知するプラグイン.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from pymongo import Connection | |
from lib.core import Filter | |
class Deleted(Filter): | |
def init(self): | |
self.watch = [] # 監視対象のスクリーンネームを入れる. 空なら全部通知 | |
addr = "localhost" | |
port = 27017 | |
db_name = "twitter" | |
self.connection = Connection(addr, port) | |
self.col = self.connection[db_name].tweet | |
def filter(self, packet): | |
data = packet["data"] | |
if not isinstance(data, dict): | |
return None | |
if data.get("event") == "delete": | |
try: | |
tweet = self.col.find({u"id":data["id"]})[0] | |
except IndexError: | |
return None | |
detail = {"user":tweet[u"user"][u"screen_name"], | |
"post":tweet[u"text"]} | |
if self.watch != [] and str(detail["user"]) not in self.watch: | |
return None | |
self.send(u"%(user)s deleted: %(post)s" % detail, exclude = ["favbot"]) | |
def cleanup(self): | |
self.connection.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment