Skip to content

Instantly share code, notes, and snippets.

@catupper
Created September 28, 2012 12:27
Show Gist options
  • Select an option

  • Save catupper/3799527 to your computer and use it in GitHub Desktop.

Select an option

Save catupper/3799527 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import sys
import tweepy
import json
import pymongo
con = pymongo.Connection(host = ,port = )
username = ""
password = ""
db = con.death
auth = tweepy.auth.BasicAuthHandler(username, password)
class CustomStreamListener(tweepy.StreamListener):
def on_data(self, data):
if data.startswith("{"):
p = json.loads(data)
if u'text' in p:
for x in xrange(6):
p[[u'day', u'month', u'dait', u'time', u'zone', u'year'][x]] = p[u'created_at'].split()[x]
if db.tweets.find({u'id':p[u'id']}).count() == 0:
db.tweets.insert(p)
def on_error(self, status_code):
print >> sys.stderr, 'Encounted Exception with status code:', status_code
return True
def on_timeout(self):
print >> sys.stderr, 'Timeout...'
return True
streaming_api = tweepy.Stream(auth ,CustomStreamListener(), timeout=None)
streaming_api.filter(follow = None, track = ["突然の", "人人人"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment