Skip to content

Instantly share code, notes, and snippets.

@non117
Created August 2, 2012 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save non117/3235754 to your computer and use it in GitHub Desktop.
Save non117/3235754 to your computer and use it in GitHub Desktop.
Boxnya plugin. mongodbと連携してTLのdeletedを通知するプラグイン.
# -*- 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