¿Cómo usar el API de pollstr?

(Información en inglés)
import json
                import requests

                #Get the text data into a list
                text = ['some text', 'some bad text', 'some good text', 'some text', 'text text text', 'good good text good']

                #Explore Keywords

                #Prepare data to be sent in the POST request to Pollstr.
                #First, 'url' and 'data' - the latter should contain 'username' and 'language'

                #User the following URL for 'Keywords'
                url_keywords = "http://pollstr.io:8080/api/explore/keywords/"
                data_keywords = {'username': 'julio', 'language': 'english', 'no_keywords':''}
                #Specify the number of keywords you'd like to get from pollstr. 'no_keywords':''
                #returns a count for every keyword.

                #Second, prepare 'data' and 'text' to be sent.
                data_to_analyze = {'data': data_keywords, 'text': text, 'to_remove': []}

                #Serialize the data
                data_to_analyze = json.dumps(data_to_analyze)

                #Send a POST request to Pollstr
                r = requests.post(url = url_keywords, data = data_to_analyze)

                #Wait for it...
                print json.loads(r.text)

                #Explore clusters

                #Use the following URL for 'Cluster'
                url_cluster = 'http://pollstr.io:8080/api/explore/cluster/'
                #Notice you don't have to specify "no_keywords" in Cluster
                data_cluster = {'username': 'julio', 'language': 'english'}

                #Second, prepare 'data' and 'text' to be sent.
                data_to_analyze = {'data': data_cluster, 'text': text}

                #Serialize the data
                data_to_analyze = json.dumps(data_to_analyze)

                #Send a POST request to Pollstr
                r = requests.post(url = url_cluster, data = data_to_analyze)
                print r.text
                #Wait for it...

                #Obtain your analysis
                print json.loads(r.text)

                #Explore sentiment
                #Use the following URL for 'Sentiment'
                url_sentiment = 'http://pollstr.io:8080/api/explore/sentiment/'
                #Notice you don't have to specify "no_keywords" in Sentiment
                data_sentiment = {'username': 'julio', 'language': 'english'}

                #Second, prepare 'data' and 'text' to be sent.
                data_to_analyze = {'data': data_sentiment, 'text': text}

                #Serialize the data
                data_to_analyze = json.dumps(data_to_analyze)

                #Send a POST request to Pollstr
                r = requests.post(url = url_sentiment, data = data_to_analyze)

                #Wait for it...

                #Obtain your analysis
                print json.loads(r.text)
                

Obtains the 'keywords' out of a list containing text.

Resource URL:

http://pollstr.io/api/explore/keywords/

  • Resource Information:

  • Response format: JSON
  • Requires authentication? Yes (username only)
  • Rate limited? Yes
  • Parameters:

  • 'data' (required): Sends credentials and other information to do the analysis.
  • 'username' (required): Nested within 'data'. Username.
  • 'language' (optional): Nested within 'data'. Language to perform the analysis.
  • 'no_keywords' (optional): Nested within 'data'. Number of keywords to be returned.
  • 'text' (required): List of text to be sent to perform an analysis.
Example Request:

POST
http://pollstr.io/api/explore/keywords/text.json

Example Response:

{"financial": 57, "unemployment": 56, "lack": 44, "people": 41, "immigration": 47, "recession": 38, "economic": 120, "banks": 45, "situation": 48, "economy": 204}

Obtains the 'clusters' and topics within a list containing text.

Resource URL:

http://pollstr.io/api/explore/cluster/

  • Resource Information:

  • Response format: JSON
  • Requires authentication? Yes (username only)
  • Rate limited? Yes
  • Parameters:

  • 'data' (required): Sends credentials and other information to do the analysis.
  • 'username' (required): Nested within 'data'. Username.
  • 'language' (optional): Nested within 'data'. Language to perform the analysis.
  • 'text' (required): List of text to be sent to perform an analysis.
Example Request:

POST
http://pollstr.io/api/explore/cluster/text.json

Example Response:

{"clusters": {"1": {"count": 1, "topics": ["unemployment", "rise", "system", "recession", "banking"]}, "0": {"count": 64, "topics": ["unemployment", "economic", "employment", "economy", "unemployment,"]}, "3": {"count": 202, "topics": ["economy", "state", "confidence", "lack", "immigration"]}, "2": {"count": 226, "topics": ["immigration", "recession", "money", "lack", "brown"]}, "5": {"count": 38, "topics": ["credit", "crunch", "gun", "knife", "people"]}, "4": {"count": 149, "topics": ["government", "people", "lack", "recession", "money"]}, "7": {"count": 120, "topics": ["economic", "situation", "crisis", "downturn", "climate"]}, "6": {"count": 78, "topics": ["banks", "banking", "system", "money", "getting"]}, "8": {"count": 73, "topics": ["financial", "finance", "crisis", "situation", "problems"]}}}