DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

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

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

The Problem

As developers, we often struggle with scraping data from various sources to analyze sentiment, especially in areas like immigration, where public opinion can shift rapidly. The DIY scraping process can be tedious, requiring constant updates and maintenance. You want to keep your finger on the pulse without getting bogged down in the mechanics of gathering the data.

The Solution

Enter the Pulsebit API, which simplifies your life with a single endpoint that provides real-time sentiment analysis. With just a few lines of Python code, you can access timely sentiment data about immigration trends. For instance, the current sentiment score for immigration sits at +0.00 with a momentum of +0.15. This indicates a rising sentiment, albeit with a confidence of 0.87. You can easily tap into this data without the hassle of scraping or cleaning it yourself.

The Code

To get started, you'll need to make a GET request to the /news_semantic endpoint. Below is a Python snippet using the requests library to fetch immigration sentiment data from Pulsebit.

import requests

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


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

# Set your parameters
params = {
    'topic': 'immigration',
    'region': 'global'
}

# 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

Reading the Response

Let’s break down the fields in the response you’ll receive:

  • sentiment_score: This is currently +0.00, reflecting neutral sentiment. However, the rising direction indicates potential shifts.
  • momentum_24h: At +0.15, this suggests an upward trend in sentiment, which is noteworthy given the current neutral score.
  • confidence: Standing at 0.87, this means you can trust the data to a high degree.
  • sentiment_index_0_100: This gives you a score of 35.0, positioning sentiment on the lower end of the scale, yet it’s critical to note that it’s rising.
  • direction: The sentiment is categorized as “rising”, which could be a signal of changing public opinion.
  • semantic_clusters: With 19 clusters, this indicates a rich variety of discussions around the topic.
  • region: The data is global, making it applicable across various contexts.
  • semantic_similarity_avg: At 0.222, this measures how closely related the discussions are within the clusters.

Three Use Cases

  1. Algo Alert: Set up an automated alert that triggers when the sentiment score rises above a certain threshold. For instance, if the score goes from +0.00 to +0.05, this could indicate a significant shift worth monitoring.

  2. Slack Bot: Create a Slack bot that sends daily updates on immigration sentiment. When the momentum increases, your team gets an instant message, keeping everyone in the loop.

  3. Dashboard: Build a dashboard that visualizes this data over time. Monitor sentiment scores, momentum, and clusters to better understand the public’s evolving perception of immigration.

Get Started

Ready to dive in? Check out the Pulsebit API documentation for complete details on using the /news_semantic endpoint. This API empowers you to efficiently track sentiment shifts without the headache of traditional data scraping.


In summary, the current immigration sentiment data shows a neutral score with a rising momentum. While this may seem unremarkable at first glance, the combination of a rising direction with high confidence suggests that changes are on the horizon. Using the Pulsebit API, you can proactively monitor these shifts and take action as needed.

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)