<commit_before><commit_msg>article extraction and sentiment analysis<commit_after>import unirest
from goose import Goose

mashape_auth = "YOUR_MASHAPE_API_KEY"
topics = ["economy", "gold", "TATAMOTORS", "DRREDDY"]
unirest.timeout(10)
g = Goose({'browser_user_agent': 'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36'})

for t in topics:
	print t
	response = unirest.get("https://stockviz.p.mashape.com/news/news", 
		params={
			"symbol": t
		},
		headers={
	    		"X-Mashape-Authorization": mashape_auth,
	    		"Accept": "application/json"
  		}
	);
	
	if response.code == 200:
		for r in response.body:
			if r.has_key('HEADLINE') and r.has_key('SOURCE'):
					
				article = g.extract(url=r['SOURCE'])
				cleaned = article.cleaned_text.encode('ascii', 'ignore')
				
				response2 = unirest.get("https://loudelement-free-natural-language-processing-service.p.mashape.com/nlp-url/",
					params={
						"url": r['SOURCE']
					},
					headers={
						"X-Mashape-Authorization": mashape_auth,
						"Accept": "application/json"
					}
				);
				
				sentiment=""
				if response.code == 200:
					sentiment = response2.body["sentiment-text"]
					
				print r['HEADLINE'].encode('cp850', errors='replace'), "[", sentiment.upper(), "]"
				print cleaned
				print "========================================="
	else:
		print "response: ", response.code, ". skipping..."
{'fraction_non_alphanumeric': 0.18954703832752615, 'fraction_numerical': 0.027177700348432057, 'mean_word_length': 3.5587301587301585, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2964356', 'n_tokens_mistral': 622, 'n_tokens_neox': 496, 'n_words': 92}