-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitterMinig.py
59 lines (43 loc) · 1.46 KB
/
twitterMinig.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
'''
QUITO
==============
'''
import couchdb
import sys
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import json
##########API CREDENTIALS ############ Poner sus credenciales del API de dev de Twitter
ckey = "WN03Hf81cA7549Q2CPxVWYBMC"
csecret = "HyQMWqV6xZ5ImmtJjk0jY59irnyim14ow3s7d9T5bKoi3ieMxp"
atoken = "45447970-3yJGmuC1QsJZW1bDLbyl34hjOm9wenayCUFVt08gn"
asecret = "ttZCrRVFxXp8ECTOsZlnTasLygf3bnnJ5eRJzwam2HGF2"
class listener(StreamListener):
def on_data(self, data):
dictTweet = json.loads(data)
try:
dictTweet["_id"] = str(dictTweet['id'])
doc = db.save(dictTweet)
print "SAVED" + str(doc) +"=>" + str(data)
except:
print "Already exists"
pass
return True
def on_error(self, status):
print status
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
URL = sys.argv[1]
db_name = sys.argv[2]
'''========couchdb'=========='''
server = couchdb.Server('http://'+URL+':5984/') #() poner la url de su base de datos
try:
print db_name
db = server[db_name]
except:
sys.stderr.write("Error: DB not found. Closing...\n")
sys.exit()
'''===============LOCATIONS=============='''
twitterStream.filter(locations=[-78.593445,-0.370099,-78.386078,-0.081711]) #QUITO