-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextMinner.py
65 lines (45 loc) · 1.54 KB
/
TextMinner.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
from nytimesarticle import articleAPI
import twitter
from TwitterSearch import *
#sys.__stdout__ = sys.stdout
api = articleAPI('10e395709e384996a152bc796f21d20f')
a = []
def Scrapper(x):
global a
for i in range (x):
articles = api.search(q="google", fq = {'headline':'google'},
begin_date='20100124',
end_date="20180124",
sort="oldest",
page = i,
)
print(i)
a.append(articles)
#Saving the articles
with open('your_file.txt', 'w',encoding='utf-8') as f:
for item in a:
f.write("%s\n" % item)
def parse_articles(articles):
'''
This function takes in a response to the NYT api and parses
the articles into a list of dictionaries
'''
news = []
for i in articles['response']['docs']:
dic = {}
dic['headline'] = i['headline']['main'].encode("utf8")
dic['snippet'] = i['snippet']
dic['date'] = i['pub_date'][0:10] # cutting time of day.
news.append(dic)
return(news)
def framer(articles):
articleinfo = parse_articles(articles)
for i in articleinfo:
info = textprocessor(i.get('snippet'))
date = i.get('date')
datel.append(date)
#print(date)
if (info not in articleList) and (len(info) > 4):
articleList.append(info)
dateList.append(date)
#def twitterMiner()