-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitterStreamToDb.py
38 lines (30 loc) · 1.01 KB
/
twitterStreamToDb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# To run this code, first edit config.py with your configuration
#
#!/usr/bin/python
# -*- coding: utf-8 -*-
import tweepy
import string
import sqlite3
import time
import config
import sqliteOperations
class MyListener(tweepy.StreamListener):
"""Custom StreamListener for streaming data."""
def on_data(self, data):
try:
sqliteOperations.twitterCreateSqliteTable(data);
return True
except BaseException as e:
config.logger.error("Error on_data: %s" % str(e))
time.sleep(5)
return True
def on_error(self, status):
config.logger.error(status)
return True
def startTwitterStreamToDb():
config.logger.info(config.STEP_1_QUERY)
auth = tweepy.OAuthHandler(config.CONSUMER_KEY, config.CONSUMER_SECRET)
auth.set_access_token(config.ACCESS_TOKEN, config.ACCESS_SECRET)
api = tweepy.API(auth)
twitter_stream = tweepy.Stream(auth, MyListener())
twitter_stream.filter(languages=["tr"],track=[config.STEP_1_QUERY])