DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

How to Detect Business Sentiment Shifts with the Pulsebit API (Python)

How to Detect Business Sentiment Shifts with the Pulsebit API (Python)

The Problem

If you've ever tried scraping sentiment data for business news, you know how painful it can be. Most solutions are either too complex, require endless maintenance, or simply can't capture the nuances of sentiment changes in real-time. You end up juggling multiple libraries or APIs, struggling with rate limits, and sifting through noise. It's a headache that distracts you from building your actual application.

Right now, the sentiment score for business is sitting at +0.42 with a momentum of +0.85. That’s a noticeable spike that can give you actionable insights. But how do you tap into this data without the hassle?

The Solution

Enter the Pulsebit API. With its GET /news_semantic endpoint, you can access comprehensive sentiment data without breaking a sweat. This endpoint is a game-changer, offering you real-time insights into business sentiment using a straightforward API call.

The Code

Here’s how you can fetch sentiment data using Python. Make sure you have the requests library installed:

import requests

def get_business_sentiment():
    url = "https://pulsebit.lojenterprise.com/api/v1/news_semantic"
    params = {
        "topic": "business"
    }

    response = requests.get(url, params=params)

    if response.status_code == 200:
        return response.json()
    else:
        print(f"Error: {response.status_code}")
        return None

data = get_business_sentiment()
print(data)
Enter fullscreen mode Exit fullscreen mode

This code snippet will give you access to the latest sentiment data for business. Easy, right?

Reading the Response

Once you hit the endpoint, you'll receive a JSON response like this:

{
    "TOPIC": "business",
    "momentum_24h": 0.850,
    "sentiment_score": 0.425,
    "confidence": 0.870,
    "sentiment_index_0_100": 71.25,
    "direction": "rising",
    "semantic_clusters": 0,
    "region": "global",
    "semantic_similarity_avg": 0.204
}
Enter fullscreen mode Exit fullscreen mode

Let’s break down what you get:

  • TOPIC: This indicates the subject area, which is "business" in our case.
  • momentum_24h: A momentum score of +0.85 suggests a strong upward trend in sentiment. This is particularly noteworthy because it indicates a recent surge in positive sentiment compared to historical norms.
  • sentiment_score: The score of +0.425 reflects the current mood surrounding business topics.
  • confidence: At 0.870, this indicates a high degree of certainty in the sentiment measurement.
  • sentiment_index_0_100: A score of 71.25 suggests that sentiment is leaning positively, which is significant.
  • direction: "Rising" confirms the upward trend in sentiment.
  • semantic_clusters: A count of 0 means there are no significant clusters detected; sentiment is straightforward rather than nuanced.
  • region: Global indicates that this sentiment is not isolated to a specific geographical area.
  • semantic_similarity_avg: With a score of 0.204, it shows the average similarity of the topics being discussed, which can help you gauge how consistent the sentiment is.

Three Use Cases

  1. Algo Alert: Set up an alert system that triggers when sentiment momentum crosses a certain threshold (e.g., above +0.8). This could notify you of a significant shift in business sentiment, helping you make timely decisions.

  2. Slack Bot: Integrate this API into a Slack bot that posts daily updates on business sentiment. Use the sentiment score and momentum to keep your team informed without them needing to check manually.

  3. Dashboard: Build a simple dashboard that visualizes sentiment trends over time. Use the sentiment_index_0_100 to plot how business sentiment evolves, allowing you to quickly assess shifts at a glance.

Get Started

Ready to dive in? Check out the Pulsebit API documentation to explore more and start building. With the right tools, you can easily identify sentiment shifts and make data-driven decisions without the hassle of DIY scraping.

Top comments (0)