This guide will help you fetch earnings (net income) data for all 102 companies in your dataset.
Recommended: Financial Modeling Prep (FMP)
- Free tier: 250 API calls/day (perfect for 102 companies!)
- Get your key: https://site.financialmodelingprep.com/developer/docs
- Click "Get my Free API Key" → Sign up → Copy your API key
On Mac/Linux:
export FMP_API_KEY="your_api_key_here"On Windows (PowerShell):
$env:FMP_API_KEY="your_api_key_here"Option A: Python (Recommended)
cd /Users/gokhanturhan/Documents/GitHub/sp100-financial-tracker
python3 fetch-earnings.pyOption B: Node.js
cd /Users/gokhanturhan/Documents/GitHub/sp100-financial-tracker
node fetch-earnings.jsThe script will:
- ✅ Fetch earnings for all 102 companies
- ✅ Save to both
data/financial_data.jsonandpublic/data/financial_data.json - ✅ Show progress and summary
Then deploy:
git add .
git commit -m "Add earnings data for all companies"
git push- Reads your existing
financial_data.json - Fetches net income (earnings) for each company from FMP API
- Adds
earningsfield to each company object - Skips companies that already have earnings data
- Saves updated JSON files
- Shows summary: processed, failed, API calls used
- Free: 250 calls/day
- Signup: https://site.financialmodelingprep.com/developer/docs
- Pro: Most reliable, comprehensive data
- Free: 25 calls/day
⚠️ (only ~25 companies per day) - Signup: https://www.alphavantage.co/support/#api-key
- Con: Would take 4+ days to complete all companies
- Free: Unlimited (but unreliable, often blocks automation)
- No signup needed
- Con: Frequently fails, data may be inconsistent
If you have more than 250 companies or hit daily limits:
# Process 50 companies at a time
python3 fetch-earnings.py --batch 50Run this daily until all companies are processed. The script automatically resumes from where it left off.
======================================================================
EARNINGS DATA FETCHER - Financial Modeling Prep
======================================================================
Processing companies 1 to 102 of 102
[1/102] NVIDIA Corporation (NVDA)
⊘ Already has earnings: $29.76B
[2/102] Microsoft Corporation (MSFT)
⊘ Already has earnings: $88.14B
[3/102] Apple Inc. (AAPL)
⊘ Already has earnings: $101.96B
[4/102] Amazon.com Inc. (AMZN)
⊘ Already has earnings: $30.43B
...
[7/102] Broadcom Inc. (AVGO)
✓ Fetched: $12.63B (FY2024)
...
======================================================================
SUMMARY
======================================================================
Total companies: 102
✓ Processed: 102
✗ Failed: 0
API calls used: 96 / 250 daily limit
Remaining: 154
Done! ✨
After fetching earnings data:
# 1. Check what changed
git status
# 2. Stage all changes
git add data/financial_data.json public/data/financial_data.json
# 3. Commit
git commit -m "Add earnings data for all companies"
# 4. Push to deploy
git push origin mainCloudflare Pages will automatically rebuild and deploy your site with the new earnings data!
- Make sure you exported the environment variable in your current terminal session
- Check:
echo $FMP_API_KEY(should show your key)
- You've hit the daily limit
- Wait 24 hours or run in batch mode tomorrow
- The script will resume where it left off
- Normal! Some companies may have limited data
- The script will list failed companies at the end
- You can manually add earnings for these later
- Install Python 3: https://www.python.org/downloads/
- Or use Node.js version:
node fetch-earnings.js
Your company cards will now show earnings data like this:
Apple Inc. (AAPL)
━━━━━━━━━━━━━━━━━━━
Capex: $11.10B
Revenue: $394.33B
Earnings: $101.96B ← NEW!
Market Cap: $3.15T
Happy coding! 🚀