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)

Sustainability sentiment just hit an intriguing point: a sentiment score of 0.00 with a momentum of +0.40. This indicates a rising trend in sustainability discussions, but the sentiment itself is neutral. This unusual combination is worth digging into, especially if you're looking to tap into real-time sentiment shifts for your projects. Let's explore how you can leverage the Pulsebit API to get ahead of trends without drowning in DIY scraping pain.

The Problem (DIY Scraping Pain)

If you've ever attempted to scrape sentiment data from news articles or social media platforms, you know the headache it can bring. From handling different content formats to managing rate limits and parsing complex HTML structures, scraping can be a time sink. You need accurate data, but the effort can often feel disproportionate to the reward. That's where the Pulsebit API comes in.

The Solution (Pulsebit API — One Endpoint)

Pulsebit simplifies this process with a single, powerful endpoint: GET /news_semantic. Instead of scraping multiple sources, you can pull sentiment data directly with a few lines of Python code. This API provides not just sentiment scores but also vital context like momentum, confidence, and semantic clusters—all in one tidy package.

The Code (Python GET /news_semantic)

Here's how you can get started using the Pulsebit API to fetch sustainability sentiment data:

import requests

# Set your API key and endpoint
API_KEY = 'your_api_key_here'
url = 'https://pulsebit.lojenterprise.com/api/news_semantic'

# Define the parameters
params = {
    'topic': 'sustainability',
    'region': 'us'
}

# Make the request
headers = {
    'Authorization': f'Bearer {API_KEY}'
}
response = requests.get(url, headers=headers, params=params)

# Check if the request was successful
if response.status_code == 200:
    data = response.json()
    print(data)
else:
    print(f"Error: {response.status_code} - {response.text}")
Enter fullscreen mode Exit fullscreen mode

Reading the Response

Understanding the API response is crucial for interpreting sentiment data effectively. Here’s a breakdown of the key fields you’ll encounter:

  • topic: The specific subject you're querying, in this case, sustainability.
  • momentum_24h: The recent momentum score (+0.400) indicates a rising interest in sustainability.
  • sentiment_score: A neutral sentiment score (+0.000) suggests that while discussions are increasing, they aren't heavily positive or negative.
  • confidence: The confidence level (0.870) indicates a high degree of certainty in the sentiment analysis.
  • sentiment_index_0_100: This index (61.25) shows the relative positivity of discussions on a scale from 0 to 100.
  • direction: The direction (rising) confirms that sentiment discussions are increasing.
  • semantic_clusters: The number of unique themes or subtopics (20) in the sustainability discourse.
  • region: Geographical focus, which is the US in this case.
  • semantic_similarity_avg: The average similarity score (0.245) between the different clusters.

Geographic detection output for sustainability filter. No ge
Geographic detection output for sustainability filter. No geo data leads by article count. Bar colour: sentiment direction. Source: Pulsebit articles[].country.

Three Use Cases

  1. Algo Alert: Set up an alert mechanism that triggers when the sentiment score changes significantly. For example, if the sentiment shifts to a negative score, you can automate a response in your system.

  2. Slack Bot: Create a Slack bot that pings your team when significant shifts happen in sustainability sentiment. This keeps everyone in the loop without manual checks.

  3. Dashboard: Integrate the Pulsebit data into a dashboard for real-time monitoring. Visualize sentiment trends over time alongside momentum and confidence levels to spot anomalies.

Get Started

Ready to dive in? Check out the Pulsebit documentation at pulsebit.lojenterprise.com/docs to set up your access and start making API calls. With this tool in your arsenal, you’ll be able to react quickly to sentiment shifts in sustainability, turning data into actionable insights without the hassle of DIY scraping.

Left: Python GET /news_semantic call for 'sustainability'. R
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.

By focusing on the current data trend, you can leverage this information to stay ahead in your projects and initiatives.

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)