forked from alfcrisci/streamallertameteo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
streamer_allertameteo.py
76 lines (53 loc) · 1.9 KB
/
streamer_allertameteo.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import sys
import tweepy
import webbrowser
import sqlite3 as lite
# Query terms
sqlite3file='stream_allertameteo.sqlite'
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_TOKEN = ''
ACCESS_TOKEN_SECRET = ''
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 IF NOT EXISTS TWEETS(txt text, author text, created int, source text, id_str text,retweet_count text,favorite text)")
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
try:
cur.execute("INSERT INTO TWEETS VALUES(?,?,?,?,?,?,?)", (status.text, status.author.screen_name, status.created_at, status.source,status.id_str,str(status.retweet_count),str(status.favorited),))
con.commit()
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
track_meteo=['#allertameteo',
'#allertameteoLIG',
'#allertameteoTOS',
'#allertameteoPM',
'#allertameteoLAZ',
'#allertameteoER',
'#allertameteoMAR',
'#allertameteoUM',
'#allertameteoABR',
'#allertameteoMOL',
'#allertameteoCAM',
'#allertameteoBAS',
'#allertameteoPUG',
'#allertameteoCAL',
'#allertameteoSIC',
'#allertameteoSAR',
'#allertameteoLOM',
'#allertameteoVEN',
'#allertameteoTAA',
'#allertameteoFVG',
'#allertameteoTS']
streaming_api = tweepy.streaming.Stream(auth, CustomStreamListener(), timeout=60)
print >> sys.stderr, 'Filtering the public timeline for "%s"' % (' '.join(track_meteo),)
streaming_api.filter( track=track_meteo,languages = ["it"])