A Discord bot that monitors the GradCafe economics section and posts new updates to a Discord channel.
- Scrapes GradCafe for new economics postings
- Stores messages in SQLite database
- Posts new messages to Discord channel
- Runs continuously with configurable check interval
- No external dependencies (R scripts or cron jobs)
pip install -r requirements.txtCopy the example environment file:
cp .env.example .envEdit .env and fill in your credentials:
DISCORD_TOKEN: Your Discord bot tokenDISCORD_CHANNEL_ID: The Discord channel ID where messages will be postedCHECK_INTERVAL_SECONDS: How often to check for new messages (default: 60)DB_PATH: Path to SQLite database file (default: gradcafe_messages.db)
Run the seed script to populate the database with current GradCafe postings:
python seed_database.pyThis will scrape GradCafe once, store all current postings, and mark them as already posted to avoid sending duplicates to Discord.
python bot.pyThe bot will:
- Initialize the database
- Check GradCafe every
CHECK_INTERVAL_SECONDSseconds - Store new messages in the database
- Post unposted messages to Discord
For deployment on cloud servers (DigitalOcean, Google Cloud, etc.):
- Set environment variables in your server's configuration
- Use a process manager like
systemdorsupervisorto keep the bot running - Ensure the bot restarts automatically if it crashes
Example systemd service file:
[Unit]
Description=GradCafe Discord Bot
After=network.target
[Service]
Type=simple
User=youruser
WorkingDirectory=/path/to/grab-cafe
Environment="DISCORD_TOKEN=your_token"
Environment="DISCORD_CHANNEL_ID=your_channel_id"
ExecStart=/usr/bin/python3 bot.py
Restart=always
[Install]
WantedBy=multi-user.targetbot.py: Main Discord bot with background taskscraper.py: Web scraping logic for GradCafedatabase.py: SQLite database operationsseed_database.py: One-time seed script to populate databaserequirements.txt: Python dependencies.env.example: Template for environment variables
grab-cafe-bot.py: Old bot implementationparse-grad-cafe.R: Old R scraping scriptmessages.csv: Old message storagenew_messages.csv: Old temporary message file