Skip to content

Latest commit

 

History

History

python

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Newsboard client library (python)

Library to get un-analyzed news entries from the Newsboard, publish sentiment scoring results and news entries.

Prerequisites

python requests library (http://docs.python-requests.org/en/master/)

pip install requests

Usage

Client instance with the host/url to the NewsBoard WebService and token generated by an administrator.

client = newsboard.Client("http://localhost:8080", "YOUR TOKEN GOES HERE");

Use get_newsentries() to get all un-analyzed news entries for the given token.

entries = client.get_newsentries()                      # gets the un-analyzed news entries for the given token

for entry in entries:
    print(entry.get_title())                            # entry is type of newsboard.models.NewsEntry

To publish new sentiment scoring results use publish_result(id, result) with the id of the news entry.

# scores are from range [-100, +100]

result = newsboard.models.AnalyzerResult()

result.set_score(100)                                   # overall score 100
result.add_sentence(0, 15, 2)                           # from start index 0 to 15 score 2
result.add_sentence(16, 32, -6)                         # from start index 16 to 32 score -6

client.publish_result("mt-21731035", result)

To publish news entries use publish_news(entry).

entry = newsboard.models.NewsEntry()

entry.set_id("test")
entry.set_date("2017-03-26T20:23:00Z")
entry.set_source("Mindener Tageblatt")
entry.set_image("http://placehold.it/500x500")
entry.set_url("http://heise.de")
entry.set_title("Title of the news entry")
entry.set_content("Content of the news entry")

client.publish_news(entry)