A powerful automation tool that scrapes data from websites, processes it, and seamlessly uploads it to a MySQL database. Features a real-time web dashboard for monitoring and managing your automation tasks.
- Web Scraping: Efficiently scrapes data from websites using BeautifulSoup and lxml
- Data Processing: Cleans, processes, and transforms scraped data
- Database Integration: Posts data directly to MySQL database via API
- Smart Checkpointing: Remembers processed URLs to avoid duplicate scraping
- Web Dashboard: Real-time Flask-based monitoring interface
- Error Tracking: Automatically logs failed uploads for retry and debugging
- Thread-based Execution: Non-blocking background task execution
- Comprehensive Logging: Detailed logging to both console and file
- Docker Ready: Includes Dockerfile for containerized deployment
- Configuration-driven: Easy configuration via JSON
- Backend: Python 3.x
- Web Framework: Flask
- Database: MySQL
- Data Scraping: BeautifulSoup4, Requests, lxml
- Data Processing: Pandas
- Containerization: Docker
- Database Driver: mysql-connector-python
Before you begin, ensure you have the following installed:
- Python 3.7+
- MySQL Server 5.7+ or MySQL 8.0+
- pip (Python package manager)
- Git (for cloning the repository)
git clone https://github.com/yourusername/Automate_Bot.git
cd Automate_Bot# On Windows
python -m venv venv
venv\Scripts\activate
# On macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtCREATE DATABASE blog_web;Ensure you have the necessary tables created in your MySQL database.
Create or update the config.json file with your credentials:
{
"api_url": "http://localhost/api/post-data-insertion",
"mysql_config": {
"host": "localhost",
"user": "root",
"password": "your_password",
"database": "blog_web"
},
"cookies": {
"vr_session": "your_session_cookie",
"vr_csrftoken": "your_csrf_token"
}
}Important: Never commit sensitive credentials to version control. Use environment variables or .env files for production.
python app.pyThis will:
- Read URLs from
sitemap.csv - Scrape data from each URL
- Post the data to your MySQL database
- Log all activities to
logs.txt - Track successful uploads in
checkpoint.txt - Save failed uploads to
failed_uploads.txt
python dashboard.pyThe dashboard will be available at http://localhost:5000 with features to:
- View real-time logs
- Monitor scraping progress
- Start/stop the bot
- View checkpoint status
- Track failed uploads
docker build -t automate-bot .
docker run -d -p 5000:5000 automate-botAutomate_Bot/
βββ app.py # Main orchestrator script
βββ scrapper_bot.py # Web scraping module
βββ poster_bot.py # Data posting & database module
βββ dashboard.py # Flask web dashboard
βββ config.json # Configuration file (add to .gitignore)
βββ requirements.txt # Python dependencies
βββ Dockerfile # Docker configuration
βββ checkpoint.txt # Successfully processed URLs
βββ failed_uploads.txt # Failed uploads log
βββ logs.txt # Application logs
βββ sitemap.csv # URLs to scrape
βββ templates/ # Flask HTML templates
β βββ index.html
β βββ edit_file.html
βββ static/ # Static assets
β βββ style.css
βββ README.md # This file
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Web Dashboard (Flask) β
β (dashboard.py - Port 5000) β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Main Application (app.py) β
β - Orchestrates scraping and posting flow β
β - Manages checkpointing β
β - Handles category mapping β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
ββββββββββββββββββββββββ ββββββββββββββββββββββββ
β Scraper Bot β β Poster Bot β
β (scrapper_bot.py) β β (poster_bot.py) β
β - Fetches HTML β β - Posts to API β
β - Parses with BS4 β β - MySQL connection β
β - Extracts data β β - Error handling β
ββββββββββββββββββββββββ ββββββββββββββββββββββββ
β
ββββββββββββββββββββ
β MySQL Database β
β (blog_web) β
ββββββββββββββββββββ
- Initialization: Load URLs from
sitemap.csvand previous checkpoints - Scraping: Fetch and parse web pages using BeautifulSoup
- Processing: Extract and clean data
- Categorization: Map content to predefined software categories
- Posting: Send data to API endpoint
- Storage: Save to MySQL database
- Logging: Record success/failure with detailed timestamps
- Checkpoint: Update checkpoint file to track progress
- logs.txt: Complete application logs with timestamps
- checkpoint.txt: List of successfully processed URLs (one per line)
- failed_uploads.txt: URLs that failed to upload
# View last 20 lines of logs
tail -20 logs.txt
# View all failed uploads
cat failed_uploads.txt
# Monitor logs in real-time
tail -f logs.txt2024-06-03 10:15:30,123 - INFO - Successfully scraped: https://example.com
2024-06-03 10:15:31,456 - ERROR - Failed to post data for URL: https://example.com
The bot includes robust error handling:
- Connection Timeouts: Automatically logged and added to failed uploads
- Network Errors: Gracefully handled with retry capability
- Database Errors: Logged for investigation
- Parse Errors: Handled with fallback to failed uploads list
- Concurrent Connection Pool: Manages MySQL connection pooling efficiently
# Check failed uploads
cat failed_uploads.txt
# Retry failed uploads (add URLs back to sitemap.csv)
# Then run: python app.pydocker build -t automate-bot:latest .# Interactive mode
docker run -it -p 5000:5000 automate-bot:latest
# Detached mode
docker run -d -p 5000:5000 --name my-bot automate-bot:latestYou can override config values using environment variables:
docker run -e MYSQL_HOST=db.example.com \
-e MYSQL_USER=admin \
-p 5000:5000 automate-bot:latestContributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow PEP 8 style guide
- Add docstrings to functions and modules
- Write meaningful commit messages
- Add tests for new features
Solution:
- Check MySQL server is running
- Verify credentials in
config.json - Ensure database exists
Solution:
- Check internet connection
- Verify URLs in
sitemap.csv - Check timeout settings (default: 10s)
Solution:
- Ensure port 5000 is not in use
- Check firewall settings
- Verify Flask is running
For issues, questions, or suggestions, please open an issue on GitHub or contact the maintainer.
Made with β€οΈ by Rij1