I'm working on a project right now where I'm passing in strings into this NLP API, which returns JSON objects of the string's sentiment analysis. I will admit I am a Python newbie:
http://text-processing.com/docs/sentiment.html
The documentation for calling the API is simple through a command line. It works fine when I open up terminal and run the command.
curl -d "text=great" http://text-processing.com/api/sentiment/
Running that command on terminal produces:
{"probability": {"neg": 0.59309571705919506, "neutral": 0.5403849950008478, "pos": 0.40690428294080488}, "label": "neutral"}
I am trying to figure out a way in Python to make a terminal call using the same command, and capturing the JSON object, decoding it, and using it in my code.
So far, I've found that using the below code works in Python:
import os
os.system('curl -d "text=great" http://text-processing.com/api/sentiment/')
However, when I run this line in my Python file, it prints out the JSON object. How can I save the output to a variable, and then dump string and use the JSON result in my code?
When I try:
import os
sentiment = os.system('curl -d "text=great" http://text-processing.com/api/sentiment/')
It ignores my variable assignment, and proceeds to print out the JSON object.
Any suggestions?