Skip to content

Instantly share code, notes, and snippets.

@catupper
Created September 25, 2012 13:28
Show Gist options
  • Select an option

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

Select an option

Save catupper/3781840 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='')
db = con.death
def get_oauth():
# 以下4つのキー等は適宜取得して置き換えてください。
consumer_key =""
consumer_secret = ""
access_key = ""
access_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
return auth
auth = get_oauth()
class CustomStreamListener(tweepy.StreamListener):
def on_data(self, data):
if data.startswith("{"):
p = json.loads(data)
if u'text' in p:
if u'人人人' in p[u'text'] and u'突然の' in p[u'text']:
pass
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment