A Python utility for reviewing and categorizing photo attachments on CommCareHQ forms to determine if they indicate real or fraudulent visits. The utility supports both local directory analysis and API-based photo downloading from CommCareHQ. Code developed with Cursor AI tool.
- Dual Data Sources: Analyze photos from local directories or download directly from CommCareHQ API
- Photo Filtering: Multi-select filtering by question type with photo counts
- Custom Review Categories: Define custom buckets for photo classification (e.g., "Real", "Fake", "Verified", etc.)
- Known Bad Photo Integration: Optionally include known fraudulent photos in the review set
- Randomized Review Process: Photos from the selected data source are randomized (if local, from the full local set, if api, from what is downloaded)
- CSV Export: Export review results with metadata including reviewer name and date
- Python 3.8 or higher
- Windows, macOS, or Linux
-
Clone the repository:
git clone https://github.com/theism/photo_review cd photo_review -
Install dependencies:
pip install -r requirements.txt
-
Run the application:
python photo_utility
python photo_utility--debug: Enable debug mode with verbose output--help: Show help message and exit
Examples:
# Run with debug output
python photo_utility --debug
# Show help
python photo_utility --help- Ensure you have already downloaded photos from CommCareHQ, following Multimedia Export instructions
- In the application, select "Local Directory" radio button
- Browse to a directory containing your downloaded CommCareHQ photos
- Click "Check Photo Data" to validate photo naming format
- Configure review settings and start review
- Select "CommCareHQ API" radio button
- Configure API settings:
- Domain/App Pairs File: JSON file with domain and app mappings
- Date Range: Optional start and end dates (MM/DD/YY format)
- Number of Forms: Limit forms to download (20-1000)
- Click "Check Photo Data" to download photos from API
- Configure review settings and start review
- Note that photos downloaded are saved in ..\photo_review\downloaded_photos and can be referenced via the Local Directory method in future sessions.
Create a JSON file with domain and form mappings:
{
"domain1": "app_id_1",
"domain2": "app_id_2"
}Create a .env file. If you have already done this for the Coverage tool or followed these instructions, then this step is complete. Otherwise, create a .env file with :
COMMCARE_USERNAME=your_username
COMMCARE_API_KEY=your_api_key
-
Configure Review Settings:
- Reviewer Name: Your name (saved for future sessions)
- Photo Filter: Select which types of photos to review
- Percent to Display: Percentage of photos to review (with live count)
- Review Categories: Define custom buckets for classification
- Known Bad Photos: Optionally include known fraudulent photos
-
Start Review:
- Click "Start Review" to begin the randomized review process
- Photos are displayed 3 per row with no labels
- Click category buttons to classify each set of photos
- Use "Next" to continue or "Back to Config" to modify settings
-
Export Results:
- Review results are automatically saved to CSV
- Includes form metadata, reviewer name, and review date
- Known bad photos are marked with
is_known_badcolumn
photo_review/
├── src/photo_utility/ # Main application code
│ ├── gui.py # GUI application
│ ├── scanner.py # Photo scanning logic
│ ├── filenames.py # Filename parsing
│ └── __main__.py # Application entry point
├── requirements.txt # Python dependencies
├── photo_utility # Application launcher
├── test_api.py # API testing utility
├── view_api_results.py # API results viewer
├── app_settings.txt # Application settings (auto-generated)
└── downloaded_photos/ # Downloaded photos (auto-generated)
The utility supports CommCareHQ photo naming conventions:
[json_block]-[question_id]-[user_id]-form_[form_id].jpg
[prefix]-[json_block]-[question_id]-[user_id]-form_[form_id].jpg
python test_api.pypython view_api_results.pyAutomatically created to persist:
- Reviewer name
- Last used directory
- API file path
- Review categories
Example format for API domain/form pairs:
{
"connect-experiments": "86bab9977e9afe5a61dbd30e0e500da7"
}-
"No module named 'customtkinter'":
- Run
pip install -r requirements.txt
- Run
-
"No forms found":
- Check API credentials in
.envfile - Verify domain/app pairs in input file
- Check date range settings
- Use the view_api_results test utility
- Check API credentials in
-
Photos not displaying:
- Ensure photos have proper file extensions
- Check photo naming format matches CommCareHQ conventions
-
API connection issues:
- Verify credentials in .env file
- Check network connectivity
- Verify domain names and form IDs
- Use the view_api_results test utility
Run with debug output to see detailed logging information:
python photo_utility --debugDebug mode provides:
- Detailed API request/response information
- File processing steps
- Error tracebacks
- Photo download progress
- Form parsing details
Check terminal output for detailed error messages and API responses.
- customtkinter: Modern GUI framework
- pillow: Image processing
- requests: HTTP requests for API calls
- tkcalendar: Date picker widgets
- python-dateutil: Date parsing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
See LICENSE file for details.