forked from sd17spring/InteractiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmichelle_data.py
More file actions
52 lines (41 loc) · 1.75 KB
/
michelle_data.py
File metadata and controls
52 lines (41 loc) · 1.75 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
import json
import indicoio
from indico_knock import Indico_KEY
with open('michelle_data.json', 'r') as json_data:
michelle_news = json.load(json_data)
with open('hillary_data.json', 'r') as json_data:
hillary_news = json.load(json_data)
print(len(michelle_news))
print(len(hillary_news))
indicoio.config.api_key = Indico_KEY
# print(michelle_news[0][3]['description'])
# positive = [tweet for tweet in tweet_data if tweet['sentiment']['pos'] > 0]
michelle_places = []
# there are four main search_phrases
for search_phrases in michelle_news:
# for each article in the results for each search phrase, checks if the
# the title contains the phrase "Michelle Obama"
for article in search_phrases:
if 'Michelle Obama' in article['title']:
# apply the indico place API to the title
# if there are results, keep the article
# print(article['title'])
place = indicoio.places(article['title'])
if len(place) > 0:
temp_dic = {}
temp_dic['title'] = article['title']
temp_dic['location'] = place[0]['text']
temp_dic['description'] = article['description']
temp_dic['date_pub'] = article['date_pub']
temp_dic['url'] = article['url']
michelle_places.append(temp_dic)
print(len(michelle_places))
print(michelle_places)
# print(relevant[1]['description'])
# sort list to show greatest location with highest confidence to location with lowest
# sorted_locations = sorted(k, key=lambda k: k['confidence'], reverse=True)
# print(sorted_locations)
# j = indicoio.places("U.S. first lady Michelle Obama meets with the children ", threshold=0.01)
# print(j)
# print(j[0]['text'])
# print(dir(indicoio))