Skip to content

Instantly share code, notes, and snippets.

@versae
Created November 20, 2011 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save versae/1381161 to your computer and use it in GitHub Desktop.
Save versae/1381161 to your computer and use it in GitHub Desktop.
Parse manifesto files to get positive and negative sentiment.
#!/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