Intermediate 4-5 hours · 2 APIs

Build a News Sentiment Dashboard

Analyze sentiment of trending news articles in real-time. Visualize whether coverage of a topic is positive, negative, or neutral.

APIs Used

Data Flow

USER User enters a news topic API Fetch latest articles for topic via GNews PROCESS Extract title and description text API Analyze sentiment of each article via Cloudmersive NLP PROCESS Aggregate scores into positive/negative/neutral OUTPUT Display sentiment dashboard with charts
User Action
API Call
Transform
Output

How It Works

1

Fetch the latest news articles for a given topic from GNews

2

Extract the title and description text from each article

3

Send each article's text to Cloudmersive NLP for sentiment analysis

4

Aggregate scores and display as a dashboard with charts

Code Outline

Pseudocode / JavaScript
// 1. Fetch news articles for a topic
const newsRes = await fetch(
  'https://gnews.io/api/v4/search?q=technology&token=YOUR_API_KEY&max=10'
);
const { articles } = await newsRes.json();

// 2. Analyze sentiment for each article
const sentiments = await Promise.all(articles.map(async (article) => {
  const sentRes = await fetch('https://api.cloudmersive.com/nlp-v2/analytics/sentiment', {
    method: 'POST',
    headers: { 'Apikey': 'YOUR_API_KEY', 'Content-Type': 'application/json' },
    body: JSON.stringify({ TextToAnalyze: article.title + ' ' + article.description })
  });
  const { SentimentClassificationResult } = await sentRes.json();
  return { title: article.title, sentiment: SentimentClassificationResult };
}));

// 3. Aggregate and display results
const positive = sentiments.filter(s => s.sentiment === 'Positive').length;
const negative = sentiments.filter(s => s.sentiment === 'Negative').length;
console.log(`Positive: ${positive}, Negative: ${negative}, Neutral: ${sentiments.length - positive - negative}`);

Recipe Details

Difficulty Intermediate
Time 4-5 hours
APIs Used 2

Note: These recipes are AI-generated suggestions based on API capabilities. Actual implementation may vary. Always refer to official API documentation for the latest specifications.