This Python script automatically syncs transaction data from the Classy API to a Google Sheet on a daily basis.
- Source: Classy API Campaign #656775 (approximately 14,000 transactions)
- Destination: Google Sheet (ID: 1xCr8VSAjx-7xmD0mPtWX0gxCn_72YjF_bw20ILeXDpo)
- Schedule: Daily at 6:00 AM via cron job
- Update Method: Full refresh (clears and repopulates all data)
cd classy-sync
chmod +x install.sh
./install.sh
Follow the detailed guide in setup_google_auth.md
to:
- Create a Google Cloud project
- Enable Google Sheets API
- Create service account credentials
- Share your Google Sheet with the service account
python3 test_sync.py
python3 classy_transactions_sync.py
classy-sync/
├── classy_transactions_sync.py # Main sync script
├── config.py # Configuration settings
├── requirements.txt # Python dependencies
├── setup_google_auth.md # Google API setup guide
├── install.sh # Installation script
├── test_sync.py # Connection test script
├── run_sync.sh # Cron job wrapper
├── credentials.json # Google service account credentials (you create this)
├── logs/
│ ├── classy_sync.log # Application logs
│ └── cron.log # Cron job logs
└── README.md # This file
The script is pre-configured with your Classy API credentials and Google Sheet ID. You can modify settings in config.py
:
- Classy API: Campaign ID, client credentials
- Google Sheets: Sheet ID, worksheet name
- Logging: Log file location and format
- Performance: Batch sizes, timeouts, rate limits
The script extracts and syncs the following transaction data:
Field | Description |
---|---|
Transaction ID | Unique transaction identifier |
Amount | Gross transaction amount |
Currency | Transaction currency (USD) |
Fee Amount | Processing fees |
Net Amount | Net amount after fees |
Status | Transaction status |
Type | Transaction type |
Payment Method | Payment method used |
Created Date | When transaction was created |
Updated Date | When transaction was last updated |
Member Name | Donor's full name |
Member Email | Donor's email address |
Fundraising Page Title | Associated fundraising page |
Fundraising Team Name | Associated team |
Campaign Title | Campaign name |
Designation | Fund designation |
Comment | Donor comment |
Anonymous | Whether donation is anonymous |
Recurring | Whether it's a recurring donation |
Tribute Type | Type of tribute (if any) |
Tribute Name | Name of tribute (if any) |
The installation script sets up a daily cron job that runs at 6:00 AM:
0 6 * * * /path/to/classy-sync/run_sync.sh
# View current cron jobs
crontab -l
# Edit cron jobs
crontab -e
# Run sync manually
python3 classy_transactions_sync.py
# Test connections
python3 test_sync.py
# View logs
tail -f logs/classy_sync.log
tail -f logs/cron.log
The script provides comprehensive logging:
-
Application logs:
logs/classy_sync.log
- API requests and responses
- Data processing progress
- Error details and stack traces
-
Cron logs:
logs/cron.log
- Cron job execution output
- System-level errors
-
"credentials.json not found"
- Follow
setup_google_auth.md
to create the file - Ensure it's in the correct directory
- Follow
-
"Permission denied" on Google Sheet
- Share the sheet with your service account email
- Grant "Editor" permissions
-
Classy API authentication failed
- Check your client ID and secret in
config.py
- Verify the API endpoint is accessible
- Check your client ID and secret in
-
Cron job not running
- Check cron service:
sudo service cron status
- Verify cron job exists:
crontab -l
- Check cron logs:
tail -f logs/cron.log
- Check cron service:
Run with verbose logging:
python3 -c "
import logging
logging.basicConfig(level=logging.DEBUG)
exec(open('classy_transactions_sync.py').read())
"
- Credentials: Never commit
credentials.json
to version control - API Keys: Stored in
config.py
- consider using environment variables for production - Permissions: Service account only has access to explicitly shared sheets
- Logs: May contain sensitive data - secure appropriately
The script is optimized for large datasets:
- Pagination: Handles 14,000+ transactions automatically
- Rate Limiting: Respects API limits with delays between requests
- Batch Processing: Efficient Google Sheets updates
- Error Recovery: Retries failed requests automatically
For issues or questions:
- Check the logs in
logs/
directory - Run
python3 test_sync.py
to diagnose connection issues - Review the setup guide in
setup_google_auth.md
- Verify your configuration in
config.py
This script is created for Velosano's internal use for syncing Classy API data to Google Sheets.