Skip to content

omkarrr2533/-Financial-news-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“Š Financial News Impact Analyzer

A real-time financial news analysis platform that tracks global financial institutions and their impact on Indian markets using AI-powered sentiment analysis.

๐ŸŒŸ Features

  • Real-time News Aggregation: Fetches latest news from RSS feeds and AI-powered search
  • Sentiment Analysis: Multi-layered sentiment analysis using VADER, TextBlob, and keyword matching
  • Impact Scoring: Calculates institution impact scores based on multiple factors
  • Interactive Dashboard: Beautiful, responsive UI with real-time charts
  • AI Chatbot: Ask questions about institutions, trends, and market sentiment
  • WebSocket Updates: Live data updates without page refresh

๐Ÿ—๏ธ Tech Stack

Backend:

  • Python 3.9+
  • Flask & Flask-SocketIO
  • SQLite
  • Anthropic Claude AI
  • NLTK, TextBlob, VADER

Frontend:

  • HTML5, CSS3, JavaScript (ES6+)
  • Chart.js
  • Socket.IO Client

๐Ÿ“‹ Prerequisites

  • Python 3.9 or higher
  • Anthropic API Key (Get one here)
  • Windows/Linux/macOS

๐Ÿš€ Installation & Setup

Step 1: Clone/Extract the Project

cd financial-news-bot

Step 2: Create Virtual Environment

Windows:

python -m venv venv
venv\Scripts\activate

Linux/macOS:

python3 -m venv venv
source venv/bin/activate

Step 3: Install Dependencies

pip install -r requirements.txt

Step 4: Download NLTK Data (Required for sentiment analysis)

Run Python and execute:

python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords'); nltk.download('vader_lexicon')"

Step 5: Configure Environment Variables

  1. Copy .env.example to .env:
   copy .env.example .env    # Windows
   cp .env.example .env      # Linux/macOS
  1. Edit .env and add your Anthropic API key:
   ANTHROPIC_API_KEY=sk-ant-your-actual-key-here
   SECRET_KEY=your-secret-key-change-this
  1. Generate a secure secret key (optional but recommended):
   python -c "import secrets; print(secrets.token_hex(32))"

Step 6: Create Required Directories

The application will auto-create these, but you can create them manually:

mkdir data logs

โ–ถ๏ธ Running the Application

Method 1: Using run.py (Recommended)

python run.py

Method 2: Using Flask directly

cd backend
python app.py

Expected Output:

============================================================
  FINANCIAL NEWS IMPACT ANALYZER
============================================================

๐Ÿš€ Server starting...
๐Ÿ“ URL: http://127.0.0.1:5000
๐Ÿ”ง Environment: development
๐Ÿ› Debug Mode: True

โฐ Auto-refresh interval: 1800 seconds

๐Ÿ’ก Open your browser and navigate to: http://localhost:5000

============================================================

Performing initial news fetch...
==================================================
Starting news analysis at 2024-12-25 10:30:00
==================================================
...

๐ŸŒ Accessing the Application

Open your browser and navigate to:

http://localhost:5000

Or:

http://127.0.0.1:5000

๐ŸŽฎ How to Use

1. Initial Load

  • The app automatically fetches news on startup
  • Wait 30-60 seconds for initial data processing

2. View Dashboard

  • See market summary and key statistics
  • View impact score charts
  • Check institution rankings table

3. Refresh Data

  • Click "Refresh Data" button for latest news
  • Enable "Auto-Refresh" for automatic updates every 5 minutes

4. Ask Questions

  • Use the AI chatbot to ask about:
    • Specific institutions: "Tell me about JPMorgan"
    • Top performers: "Show me the top institutions"
    • Sentiment: "Which institutions are positive?"
    • India focus: "Which institutions focus on India?"
    • Overview: "Give me a summary"

โš™๏ธ Configuration

Edit .env file to customize:

# API Configuration
ANTHROPIC_API_KEY=your-key-here

# Server Settings
HOST=127.0.0.1              # Use 0.0.0.0 for network access
PORT=5000

# Refresh Intervals
NEWS_REFRESH_INTERVAL=1800  # 30 minutes (in seconds)
QUICK_REFRESH_INTERVAL=300  # 5 minutes

# Logging
LOG_LEVEL=INFO              # DEBUG, INFO, WARNING, ERROR

๐Ÿ“ Project Structure

financial-news-bot/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ app.py                  # Main Flask application
โ”‚   โ”œโ”€โ”€ config.py               # Configuration
โ”‚   โ”œโ”€โ”€ database.py             # Database operations
โ”‚   โ”œโ”€โ”€ news_scraper.py         # News fetching
โ”‚   โ”œโ”€โ”€ sentiment_analyzer.py   # Sentiment analysis
โ”‚   โ””โ”€โ”€ impact_calculator.py    # Impact scoring
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ index.html              # Main HTML
โ”‚   โ”œโ”€โ”€ css/
โ”‚   โ”‚   โ””โ”€โ”€ style.css          # Styles
โ”‚   โ””โ”€โ”€ js/
โ”‚       โ”œโ”€โ”€ main.js            # Main logic
โ”‚       โ”œโ”€โ”€ chart.js           # Charts
โ”‚       โ””โ”€โ”€ websocket.js       # WebSocket
โ”œโ”€โ”€ data/                       # Database storage
โ”œโ”€โ”€ logs/                       # Log files
โ”œโ”€โ”€ venv/                       # Virtual environment
โ”œโ”€โ”€ .env                        # Environment variables
โ”œโ”€โ”€ .env.example               # Environment template
โ”œโ”€โ”€ requirements.txt           # Dependencies
โ”œโ”€โ”€ run.py                     # Entry point
โ””โ”€โ”€ README.md                  # readme.md file -- these file 

๐Ÿ› Troubleshooting

Issue: "ANTHROPIC_API_KEY is required"

Solution: Make sure you've set your API key in the .env file

Issue: "Module not found"

Solution:

pip install -r requirements.txt

Issue: "Port 5000 already in use"

Solution: Change PORT in .env file:

PORT=8000

Issue: "Database locked"

Solution:

# Delete the database and restart
rm data/news_cache.db
python run.py

Issue: NLTK download errors

Solution:

import nltk
nltk.download('all')

Issue: Can't access from other devices

Solution: Change HOST in .env:

HOST=0.0.0.0

Then access via: http://YOUR_IP:5000

๐Ÿ“Š API Endpoints

GET /api/news

Get latest news analysis (cached for 5 minutes)

POST /api/refresh

Force refresh news data

GET /api/status

Get system status

POST /api/chat

Send message to AI chatbot

GET /api/health

Health check endpoint

๐Ÿ”’ Security Notes

For Production Deployment:

  1. Change SECRET_KEY to a secure random value
  2. Restrict CORS origins in app.py
  3. Use HTTPS with proper SSL certificates
  4. Set DEBUG=False in production
  5. Use environment variables for all secrets
  6. Implement rate limiting on API endpoints
  7. Add authentication for admin features

๐Ÿš€ Production Deployment

Using Gunicorn (Recommended):

pip install gunicorn

gunicorn --worker-class eventlet -w 1 --bind 0.0.0.0:5000 backend.app:app

Using Docker:

Create Dockerfile:

FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "run.py"]

Build and run:

docker build -t financial-news-bot .
docker run -p 5000:5000 --env-file .env financial-news-bot

๐Ÿ“ License

This project is for educational purposes.

๐Ÿค Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

๐Ÿ“ง Support

For issues and questions:

  • Check the troubleshooting section
  • Review logs in logs/app.log
  • Check console output for errors

๐ŸŽฏ Roadmap

  • Add more news sources
  • Implement user authentication
  • Add historical data visualization
  • Email alerts for significant changes
  • Mobile app
  • Multi-language support

โš ๏ธ Disclaimer

This tool is for informational purposes only. Not financial advice. Always do your own research before making investment decisions.


Made by โค๏ธ Om Kapale

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors