-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatasetBot.py
68 lines (52 loc) · 2.11 KB
/
datasetBot.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on Dec 5, 2013
@author: Benjamin
'''
import tweepy
import readDictionary
import time
import sys
# == OAuth Authentication ==
#
# This mode of authentication is the new preferred way
# of authenticating with Twitter.
# The consumer keys can be found on your application's Details
# page located at https://dev.twitter.com/apps (under "OAuth settings")
consumer_key="Iojc087MRYfTa5d94STA"
consumer_secret="lcXr7l7bi0Jr91wmIkLtWnyZQsiJu82CkiXobLrmA"
# The access tokens can be found on your applications's D etails
# page located at https://dev.twitter.com/apps (located
# under "Your access token")
access_token="2215049539-7KIgG3CnqvrTOCUhlYfHeGVQTkwvZPHbJpMDZas"
access_token_secret="JStIVe2M3lVWr02pOpHjYJJEInYwmBSdq7ig83jwJ9YF3"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
emoticons = readDictionary.readEmoticons()
class CustomStreamListener(tweepy.StreamListener):
t0 = time.time()
output = open("Emoticons/" + str(t0), 'w')
output.close()
count = 0
def on_status(self, status):
if status.lang == "en":
output = open("tweets/emoticontweets/" + str(self.t0), 'a')
text = status.text.replace('\n','').replace('\r','') # For some reason this cleans the data better than 'rstrip'
output.write(text + '\n')
output.close()
self.count += 1
if self.count > 1000000:
return False # Stop the stream after 1000000 minutes seconds
return True #Don't kill the stream
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
###############################################################################
if __name__ == '__main__':
stream = tweepy.streaming.Stream(auth, CustomStreamListener())
stream.filter(track=emoticons)