Skip to content

Tracking Trump’s Supreme Court Blast on Media with Python

4 min read

Learn how I built a Python pipeline to capture Trump’s blast at the Supreme Court on social media, run sentiment analysis, and visualize results with a free analytics platform.

Cover image for "Tracking Trump’s Supreme Court Blast on Media with Python"

When Trump blasts Supreme Court on social media, the conversation erupts across X, Facebook, and even LinkedIn. I needed a fast, repeatable way to pull those posts, score the sentiment, and share a concise wrap‑up with my team. In this post I walk through the exact script I wrote in Python, the pitfalls I hit, and how I turned raw data into a shareable dashboard.

Why this matters: Real‑time political monitoring lets you react to public sentiment before the next headline, and a lightweight pipeline can be built with just a few libraries.

#Fetching real‑time posts about the Supreme Court blast

The first step is to collect the raw posts. X (formerly Twitter) still offers the most granular public API for keyword search, and its recent v2 endpoints let you filter by language, recentness, and even exclude retweets.

#Using the X API with Python

import os
import tweepy

client = tweepy.Client(bearer_token=os.getenv("TWITTER_BEARER_TOKEN"))

query = '"Trump" "Supreme Court" -is:retweet lang:en'
response = client.search_recent_tweets(query=query, max_results=100, tweet_fields=["created_at","author_id"])
tweets = response.data or []

for tweet in tweets:
    print(f"{tweet.id}: {tweet.text[:80]}...")

The code above pulls the latest 100 English tweets that contain both Trump and Supreme Court. Make sure you have a bearer token from the X developer portal; without it the request will be rejected.

Tip: If you want to skip the API setup, I’ve been using Social Wrapped to ingest the CSV export and instantly generate a visual summary for my stakeholders.

#Running sentiment analysis on political chatter

Once the raw text is in hand, the next challenge is to turn it into a numeric sentiment score. For quick prototypes, the textblob library is surprisingly effective.

from textblob import TextBlob

def sentiment_score(text: str) -> float:
    blob = TextBlob(text)
    return blob.sentiment.polarity  # -1 (negative) to +1 (positive)

scores = [sentiment_score(t.text) for t in tweets]
average = sum(scores) / len(scores) if scores else 0
print(f"Average polarity: {average:.3f}")

During testing I noticed that sarcasm and meme formats often skew the polarity toward neutral. A simple workaround is to filter out tweets shorter than 20 characters before scoring.

Warning: The free tier of the X API limits you to 500 requests per month. Batch your queries or cache results to avoid hitting the quota.

#Packaging the results for easy sharing

After scoring, I write the data to a CSV that can be consumed by any analytics tool. The column layout mirrors what Social Wrapped expects: timestamp,author_id,text,polarity.

import csv
from datetime import datetime

with open("scotus_blast.csv", "w", newline="", encoding="utf-8") as f:
    writer = csv.writer(f)
    writer.writerow(["timestamp", "author_id", "text", "polarity"])
    for tweet, score in zip(tweets, scores):
        writer.writerow([tweet.created_at, tweet.author_id, tweet.text, score])

I then upload the CSV to Social Wrapped, which instantly produces a shareable dashboard showing sentiment over time, top contributors, and word clouds. The platform is open‑source, so I can host the visualization behind our internal firewall if needed.

Note: The CSV format is deliberately simple; you can replace it with JSON or a database dump if your downstream tools require it.

#Automating the workflow with a cron job

Manually running the script after every news flash is tedious. I wrapped the entire process in a shell script and scheduled it with cron to execute every hour during breaking news cycles.

#!/bin/bash
export TWITTER_BEARER_TOKEN="YOUR_TOKEN_HERE"
python3 fetch_and_analyze.py
# Optional: push the CSV to a remote storage
aws s3 cp scotus_blast.csv s3://my-bucket/news-monitor/

Add the following line to your crontab (crontab -e):

0 * * * * /path/to/run_monitor.sh >> /var/log/scotus_monitor.log 2>&1

This ensures you always have the latest sentiment snapshot without lifting a finger.

#Checklist for a production‑ready pipeline

  1. Create a dedicated API app on the X developer portal.
  2. Store credentials securely (environment variables, secret manager).
  3. Implement retry logic for rate‑limit errors.
  4. Validate and clean text before sentiment scoring.
  5. Archive raw data for auditability.

For deeper reading on X’s API limits, see the official Twitter API v2 documentation. The SCOTUSblog coverage of the incident provides useful context for the keywords you might want to track: Trump blasts Supreme Court on social media - SCOTUSblog.


By stitching together a few Python libraries, an API key, and a free analytics platform, you can turn any political flashpoint—like Trump’s Supreme Court blast—into actionable insight within minutes. The same pattern applies to product launches, security incidents, or brand crises: fetch, score, visualize, and automate. Happy monitoring!

Related posts

  • Link to article
    4 min read

    Analyzing Trump’s Supercharged Social Media Footprint with Real‑Time APIs

    Explore how to capture and dissect Trump’s supercharged social media activity using X’s API, Python, and open‑source social media analytics tools.

  • Link to article
    4 min read

    Developer Guide to Social Media Opt‑Outs After Zendaya’s Exit

    When a high‑profile user like Zendaya steps away from social media, developers need to adapt their analytics pipelines. Discover practical strategies for handling opt‑outs and respecting privacy.