Created
November 20, 2011 23:36
-
-
Save versae/1381161 to your computer and use it in GitHub Desktop.
Parse manifesto files to get positive and negative sentiment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import urllib | |
import requests | |
party = "name_of_the_party" | |
lines = [] | |
for line in open("programa-%s.txt" % party , "r"): | |
l = line.strip() | |
try: | |
int(l) | |
except: | |
if l.endswith("-"): | |
lines.append(l[:-1]) | |
elif l: | |
lines.append(l) | |
program = (" ".join(lines)).split(".") | |
json = [] | |
print len(program) | |
for sentence in program: | |
response = requests.get("http://www.viralheat.com/api/sentiment/review.json?text=%s&api_key=<API_KEY>" % urllib.quote(sentence)) | |
print response.content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment