/
twitterScout.py
34 lines (29 loc) · 1.08 KB
/
twitterScout.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
import twitter
import re
from string import whitespace
from scouter import Sentence
from scouter import Paragraph
from urllib import parse
config = {}
with open("/Users/samuelbarthelemy/config.py") as f:
for line in f:
line = line.rstrip("\n")
(key, val) = line.split("=")
config[key] = val
print(config)
api = twitter.Api(access_token_key=config["access_key"], access_token_secret=config["access_secret"], consumer_key=config["consumer_key"], consumer_secret=config["consumer_secret"])
comment out to not run
query = api.GetSearch(term="hillary clinton", count=100, result_type="recent")
for result in query:
tweet = result.AsDict()["text"]
tweet = ' '.join(re.sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)", " ", tweet).split())
tweet = re.sub('RT', '', tweet)
tweet = re.sub('https', '', tweet)
tweet = re.sub('[^a-zA-Z0-9 \n\.]', '', tweet)
tweet = tweet.lstrip(whitespace)
if len(tweet) <= 0:
break
tweet = Paragraph(tweet)
tweet.breakIntoSentences()
for sentence in tweet.sentences:
sentence.submitSentence()