DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

The Problem

As developers interested in sentiment analysis, you’re probably familiar with the frustration of DIY scraping. Sifting through endless academic journals, news articles, and social media posts to gauge public sentiment on scientific topics can be a time-consuming nightmare. You might find yourself spending more time maintaining your scraping scripts than actually analyzing the data. This is where the Pulsebit API comes in—offering a streamlined solution to track sentiment in real time.

The Solution

The Pulsebit API provides a single endpoint that allows you to access sentiment data effortlessly. You can get a comprehensive view of sentiment shifts in various topics, including science. The current data shows a sentiment score of 0.00 with a momentum of +0.72—this is noteworthy because it indicates a rising sentiment trend despite a neutral score. This juxtaposition suggests that while the overall sentiment remains balanced, there’s a pronounced upward momentum that could indicate a shift in public perception or emerging trends in scientific discourse.

The Code

Getting started with the Pulsebit API is straightforward. Here's how you can fetch the sentiment data for science using Python:

import requests

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


# Define the API endpoint
url = "https://pulsebit.lojenterprise.com/api/news_semantic"

# Set parameters
params = {
    "topic": "science"
}

# Make the GET request
response = requests.get(url, 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}")
Enter fullscreen mode Exit fullscreen mode

This code snippet sets up a simple GET request to the Pulsebit API. It retrieves the sentiment data for the topic "science" and prints it out.

Reading the Response

When you receive the response, it will look something like this:

{
    "TOPIC": "science",
    "momentum_24h": 0.717,
    "sentiment_score": 0.0,
    "confidence": 0.87,
    "sentiment_index_0_100": 70.0,
    "direction": "rising",
    "semantic_clusters": 17,
    "region": "global",
    "semantic_similarity_avg": 0.302
}
Enter fullscreen mode Exit fullscreen mode

Here's a breakdown of the relevant fields:

  • TOPIC: The subject of the sentiment analysis (in this case, "science").
  • momentum_24h: A value of 0.717 indicates a strong upward trend in sentiment over the past 24 hours.
  • sentiment_score: Currently at 0.0, which suggests neutrality but is accompanied by rising momentum.
  • confidence: A high confidence level of 0.87 supports the reliability of this data.
  • sentiment_index_0_100: The index stands at 70.0, suggesting that while sentiment is neutral now, it’s currently trending positively.
  • direction: Indicates that sentiment is rising.
  • semantic_clusters: A count of 17 clusters showing diverse discussions around the topic.
  • region: Data is collected on a global scale.
  • semantic_similarity_avg: At 0.302, this indicates the average similarity across the clusters.

Three Use Cases

  1. Algo Alert: You can set up an algorithm that triggers alerts when momentum exceeds a certain threshold, such as 0.7, indicating that you should pay attention to potential shifts in public sentiment towards scientific topics.

  2. Slack Bot: Create a Slack bot that pushes updates on sentiment changes. For example, if the sentiment score moves from neutral to positive, your team can discuss the implications in real time.

  3. Dashboard: Build a dashboard that visualizes sentiment shifts over time. This could help you identify trends, spikes, or drops that deserve deeper analysis or immediate action.

Get Started

If you want to dive deeper into the Pulsebit API, check out their documentation. The API offers a wealth of data that can help you stay ahead in understanding sentiment dynamics, especially in the realm of science.

Leverage this tool to take the grunt work out of your analysis, and focus on what really matters—making sense of the data and deriving insights that can influence your projects and discussions.

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)