-
Notifications
You must be signed in to change notification settings - Fork 1
/
VictumInfo.py
91 lines (72 loc) · 3.76 KB
/
VictumInfo.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
import sys
sys.path.append(os.getcwd())
from TwitterSearch import *
import requests
from GeoInfo import VictimInfo, GeoPosition
class SearchFrame:
def __init__(self):
self.longitude = 51.7555 #Specify a box of size (x * divsize) * (y * divsize) with top left corner in pos long, lat
self.latitude = 0.0
self.x = 1
self.y = 1
self.diameter = 10 #diameter of search circles in box, in miles
def getVictims():
frame = SearchFrame()
geolocations = [[[] for i in range(0,frame.x)] for j in range(0,frame.y)]
for i in range(0,frame.x):
for j in range(0,frame.y):
tso = TwitterSearchOrder()
tso.set_keywords(["tornado", "EF", "hail", "storm", "damage", "injur", "kill", "wind", "thunder", "water", "flood", "rain", "wound", "loss", "help", "save"], or_operator=True)
tso.set_geocode(frame.longitude + milesToLat(i*frame.diameter), frame.latitude + milesToLat(j*frame.diameter), int(frame.diameter/2))
searchResults = TwitterSearch(consumer_key="eoe5TmgDTsmI0E2NpSrt7KPfg",
consumer_secret="onNO7vobeUw1piKWfmXQJwmpMKrQbzRWTeXFjKo6nZwipCPJ3r",
access_token="2491643690-UVYiYfoc3VXyQ4dc5B2VcSCMTU0hsl0www8dB7n",
access_token_secret="g8RmQzuyIA0vgxfCgTcMsSshbWYGmhmKfIO3320TQ6isY")
for tweet in searchResults.search_tweets_iterable(tso):
#print('@%s tweeted: %s' % (tweet['user']['screen_name'],tweet['text']))
geolocations[i][j].append(tweet)
geolocations = azureApi(geolocations)
returnlist = []
for i in range(0,frame.x):
for j in range(0,frame.y):
for tweet in geolocations[i][j]:
returnlist.append(VictimInfo(GeoPosition(frame.longitude + (i*frame.diameter), frame.latitude + (j*frame.diameter), int(frame.diameter/2))))
return returnlist
def azureApi(geolocs):
azurekey = "29c7bf1a559d4d2e8e83db07740b33eb"
text_analytics_base_url = "https://uksouth.api.cognitive.microsoft.com/text/analytics/v2.0/"
sentiment_api_url = text_analytics_base_url + "sentiment"
values = []
for x in geolocs:
for y in x:
for z in y:
values.append({'id': z['id'], 'text': z['text'], 'language': 'en'})
documents = { 'documents' : values}
headers = {"Ocp-Apim-Subscription-Key": azurekey}
response = requests.post(sentiment_api_url, headers=headers, json=documents)
sentiments = response.json()
threshold = 0.25
#unhappytweets = [x['id'] for x in sentiments['documents'] if x['score'] < threshold]
unhappytweets = []
for x in geolocs:
for y in x:
for z in y:
if z['id'] in unhappytweets:
y.remove(z)
return geolocs
def milesToLat(x):
return x/69.2
def getUpdateTweets():
frame = SearchFrame()
tso = TwitterSearchOrder()
tso.set_keywords(["breaking", "news", "BREAKING NEWS", "NEWS", "update", "development"], or_operator=True)
tso.set_geocode(frame.longitude + milesToLat((frame.x /2 )*frame.diameter), frame.latitude + milesToLat((frame.x / 2)*frame.diameter), int((frame.x /2 )*frame.diameter))
searchResults = TwitterSearch(consumer_key="eoe5TmgDTsmI0E2NpSrt7KPfg",
consumer_secret="onNO7vobeUw1piKWfmXQJwmpMKrQbzRWTeXFjKo6nZwipCPJ3r",
access_token="2491643690-UVYiYfoc3VXyQ4dc5B2VcSCMTU0hsl0www8dB7n",
access_token_secret="g8RmQzuyIA0vgxfCgTcMsSshbWYGmhmKfIO3320TQ6isY")
returnlist = []
for tweet in searchResults.search_tweets_iterable(tso):
returnlist.append(tweet)
return returnlist