Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import tweepy
- import webbrowser
- import sqlite3 as lite
- # Query terms
- Q = sys.argv[1:]
- sqlite3file='/var/www/twitter.lbox.com/html/stream5_log.sqlite'
- CONSUMER_KEY = 'HfYi7CoZoH3DvzHkfmau1g'
- CONSUMER_SECRET = 'CfrPYXhk1q6cT9KdcnHQyJcALg6Ba0xnD3U2MRQ8k4U'
- ACCESS_TOKEN = '501088042-y380jKOWFtpZ3RmrCQRW70dOrqrKW8YDrNbiWnJI'
- ACCESS_TOKEN_SECRET = 'syUpRCKzdkmNnxbMkqDHXHgab1ow36MPzB9FVm793fY'
- auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
- auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
- con = lite.connect(sqlite3file)
- cur = con.cursor()
- cur.execute("CREATE TABLE TWEETS(txt text, author text, created int, source text)")
- class CustomStreamListener(tweepy.StreamListener):
- def on_status(self, status):
- try:
- print "%s\t%s\t%s\t%s" % (status.text,
- status.author.screen_name,
- status.created_at,
- status.source,)
- cur.executemany("INSERT INTO TWEETS(?, ?, ?)", (status.text,
- status.author.screen_name,
- status.created_at,
- status.source)
- except Exception, e:
- print >> sys.stderr, 'Encountered Exception:', e
- pass
- def on_error(self, status_code):
- print >> sys.stderr, 'Encountered error with status code:', status_code
- return True # Don't kill the stream
- def on_timeout(self):
- print >> sys.stderr, 'Timeout...'
- return True # Don't kill the stream
- streaming_api = tweepy.streaming.Stream(auth, CustomStreamListener(), timeout=60)
- print >> sys.stderr, 'Filtering the public timeline for "%s"' % (' '.join(sys.argv[1:]),)
- streaming_api.filter(follow=None, track=Q)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement