-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFindTweets.py
More file actions
58 lines (46 loc) · 1.73 KB
/
FindTweets.py
File metadata and controls
58 lines (46 loc) · 1.73 KB
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
#author Rohan Subramaniam
from __future__ import print_function
import json
from TweetInfo import TweetInfo
from TwitterAPI import TwitterAPI
from alchemyapi import AlchemyAPI
from TwitterKeys import CONSUMER_KEY, CONSUMER_SECRET,ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET
api = TwitterAPI(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_TOKEN_KEY,ACCESS_TOKEN_SECRET)
Team1 = 'Arsenal'
count1 = 50
until = "2015-10-06"
lang = 'en'
geocode1 = "51.5072,0.1275,100mi" #Geocode of london
since = '2015-10-04'
team1_text = ""
team1_list = []
r = api.request('search/tweets', {'lang': lang, 'q': Team1, 'count': count1, 'geocode': geocode1, 'since':since, 'until':until})
for item in r:
team1_list.append(TweetInfo(item['text'],item['created_at']))
Team2 = 'Manchester United'
count2 = 50
geocode2 = "53.4667,2.2333,100mi" #geocode of Manchester
team2_text = ""
team2_list = []
r = api.request('search/tweets', {'lang': lang, 'q': Team2, 'count': count2, 'geocode': geocode2, 'since':since, 'until':until})
for item in r:
team2_list.append(TweetInfo(item['text'],item['created_at']))
#print(item['text'])
alchemyapi = AlchemyAPI()
sentiment1 = [0.0,0.0]
sentiment2 = [0.0,0.0]
counter1 = 0;
counter2 = 0;
for i in xrange(len(team1_list)):
response = alchemyapi.sentiment('html', team1_list[i].tweetString)
if response['status'] == 'OK':
response['usage'] = ''
if 'score' in response['docSentiment']:
if(float(response['docSentiment']['score']) < 0):
sentiment1[0] += 1
else:
sentiment1[1] += 1
#print('positive sentiment score: ', response['docSentiment']['score'])
counter1 += 1
else:
print('Error in sentiment analysis call: ', response['statusInfo'])