-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalchemy.py
22 lines (20 loc) · 902 Bytes
/
alchemy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import keys,json,requests
def news_list(search_query, outfile='urls.txt', count=10):
f = open(outfile,'w')
endpoint = 'https://gateway-a.watsonplatform.net/calls/data/GetNews'
payload = { 'outputMode':'json',
'start':'now-10d',
'end':'now',
'count':count,
'q.enriched.url.enrichedTitle.keywords.keyword.text':search_query,
'return': 'enriched.url.url,enriched.url.title',
'apikey':keys.alchemykey,
}
r = requests.get(endpoint,params=payload)
json_vals = r.json()
for each_story in json_vals['result']['docs']:
source = each_story['source']['enriched']['url']
f.write(source['title'].encode('utf-8') + '^' + source['url'].encode('utf-8')+'\n')
#print json.dumps(json_vals,indent=4,sort_keys=True)
if __name__ == '__main__':
news_list('india')