DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

The Problem

As developers, we often find ourselves sifting through a sea of data to gauge sentiment on specific topics, and sustainability is no exception. Historically, scraping news articles and social media posts for sentiment analysis can be a tedious and error-prone process. The constant need to maintain scrapers, handle rate limits, and parse ever-changing HTML structures makes this DIY approach a headache. You want to focus on building valuable insights, not fighting with unreliable data sources.

The Solution

Enter the Pulsebit API. With just one endpoint, you can access a wealth of sentiment data around sustainability and other topics. The /news_semantic endpoint aggregates news articles, analyzes sentiment, and provides you with structured data, all while saving you from the hassle of DIY scraping.

Let’s take a look at a recent Pulsebit API response for sustainability sentiment. The data is particularly interesting right now, as it shows a sentiment score of 0.00 with a momentum of +0.355. This suggests that while the current sentiment is neutral, there’s a rising trend in conversations and interest around sustainability.

The Code

Here’s a simple Python script to get you started with the Pulsebit API. You'll need to have requests installed to run this code:

import requests

![Left: Python GET /news_semantic call for 'sustainability'. R](https://aace88ba921016d861eaeb8858550e91.r2.cloudflarestorage.com/pulsebit-marketing/figures/g3_code_output_split_1772573313485.png)
*Left: Python GET /news_semantic call for 'sustainability'. Right: live JSON response structure. Three lines of Python. Clean JSON. No infrastructure required. Source: Pulsebit /news_semantic.*


def get_sustainability_sentiment():
    url = "https://pulsebit.lojenterprise.com/api/news_semantic"
    params = {
        'topic': 'sustainability',
        'region': 'south_africa'
    }
    headers = {
        'Authorization': 'Bearer YOUR_API_TOKEN'  # Replace with your actual API token
    }

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

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

data = get_sustainability_sentiment()
if data:
    print(data)
Enter fullscreen mode Exit fullscreen mode

Reading the Response

Here's a breakdown of the response you might receive:

  • sentiment_score: 0.000 - This indicates a neutral sentiment, meaning there’s no strong positive or negative feeling towards sustainability at this moment.

  • momentum_24h: +0.355 - This number is promising; it indicates that the sentiment is gaining traction, even if the current score is neutral.

  • confidence: 0.870 - A high confidence level (87%) in the sentiment analysis suggests that you can trust this data to inform your decisions.

  • sentiment_index_0_100: 66.38 - This index value provides a relative measure of sentiment in a normalized range, where higher values indicate higher positivity.

  • direction: rising - The sentiment is on an upward trend, which could signal an impending shift in public opinion or interest.

  • semantic_clusters: 19 - This indicates that there's a diverse range of discussions and topics related to sustainability, which can be useful for more granular analysis.

Three Use Cases

  1. Algo Alert: Set up an algorithm that triggers alerts when momentum changes significantly. For instance, if momentum exceeds +0.5, you might want to investigate further or adjust your strategy.

  2. Slack Bot: Create a Slack bot that posts daily updates on sustainability sentiment. This could include the sentiment score, momentum, and links to trending articles.

  3. Dashboard: Build a dashboard that visualizes sentiment trends over time, incorporating the sentiment index and momentum. This would help you quickly identify how sentiment evolves and responds to external events.

Get Started

If you want to dig deeper and start utilizing the Pulsebit API, check out their documentation here. It’s straightforward and will get you up and running in no time.

The current sentiment data might appear neutral at a glance, but the rising momentum is a signal worth watching. By leveraging the Pulsebit API, you can keep your finger on the pulse of sustainability sentiment without the usual scraping headaches. Get started today!

Arabic coverage led by 4.2 hours. English at T+4.2h. Confide
Arabic coverage led by 4.2 hours. English at T+4.2h. Confidence scores: Arabic 0.82, Mandarin 0.68, English 0.41 Source: Pulsebit /sentiment_by_lang.

Top comments (0)