A Python automation agent that generates dynamic Google Forms for political survey data collection in Assam Assembly Constituencies. The agent extracts survey options from Excel sheets and creates AC-specific questionnaires.
This automation agent creates comprehensive Google Forms for political surveys with:
- Bilingual support (English and Bengali)
- Dynamic AC-specific sections based on Excel data
- Automated data extraction from Excel
- Interactive command-line interface
- Complete form generation with proper structure
gform_agent/
├── main.py # All-in-one consolidated script
├── assam.xlsx # Source Excel file with all AC data
├── credentials.json # Google OAuth credentials (you need to add this)
├── credentials_template.json # Template for credentials setup
├── settings.yaml # App configuration
├── requirements.txt # Python dependencies
├── generated_forms.json # Tracking of generated forms
└── README.md # This file
-
Clone or download the project files
-
Install Python dependencies:
pip install -r requirements.txt-
Set up Google Forms API credentials:
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google Forms API and Google Drive API
- Create OAuth 2.0 credentials (Desktop application)
- Download the credentials JSON file
- Rename it to
credentials.jsonand place in project root
-
Your Excel data file (
assam.xlsx) should have these sheets:AC<>PC- AC and party dataGE2024- MP candidates dataMLA_P2- MLA candidates dataCaste_Data- Caste information
- Column C: AC numbers
- Columns H-T: Party options for each AC
- Column B: AC numbers
- Column E: MP candidate names
- Column B: AC numbers
- Column D: MLA candidate names
- Column E: Party affiliation (use 'INC' for Congress)
- Column A: AC numbers
- Column B: Caste names
-
Ensure all required files are present:
assam.xlsxwith proper data structurecredentials.jsonwith Google API credentialssettings.yamlwith configuration
-
Run the agent:
python main.py- Enter AC numbers when prompted:
Enter AC numbers separated by commas (e.g., 22,23,25,26):
> 22,23,25,26
-
Follow OAuth authentication flow (browser window will open on first run)
-
Check outputs:
- Form URL will be displayed in the console
- Metadata saved to
ac_22_23_25_26_bengali_metadata.json political_survey_agent.logcontains execution logs- Form link is ready to share!
The generated form includes:
- Bilingual welcome message (Bengali and English)
- Survey purpose explanation
- Confidentiality notice
- Agent ID (text input)
- Mobile Number (text input with validation)
- Gender (radio buttons: Male, Female)
- AC Selection (dropdown with all available ACs)
Each AC gets exactly 6 questions:
- Voting Intention: Future Assembly election preference
- 2021 Voting History: Last Assembly election choice
- 2024 Voting History: Last Lok Sabha election choice (MP candidates)
- MLA Preference: Most suitable MLA candidate
- Congress Preference: Most suitable Congress candidate
- Social Category: Caste/social class
- Family income (multiple choice)
- Interview language (multiple choice)
All questions are displayed in bilingual format (English | Bengali).
- Excel file and sheet configurations
- Google Forms API settings
- Retry and error handling parameters
- Fixed options for questions
The consolidated main.py script includes:
- ConfigLoader: Loads settings from YAML and environment
- DataValidator: Validates AC numbers and data integrity
- ExcelProcessor: Extracts data from Excel sheets
- FormGenerator: Creates and manages Google Forms via API
The agent performs comprehensive validation:
- AC Number Validation: Ensures all AC numbers are valid integers
- Data Availability: Checks each AC has data in all required sheets
- Option Validation: Removes empty/invalid options
- Error Handling: Graceful handling of missing data with fallback options
All validation logic is built into the consolidated main.py script.
- INFO: General progress and status updates
- WARNING: Data availability issues, missing options
- ERROR: Critical failures, API errors
- political_survey_agent.log: Detailed execution log
- ac_[numbers]_bengali_metadata.json: Form generation metadata for each run
- generated_forms.json: Master tracking file for all generated forms
-
"File not found" errors:
- Ensure
assam.xlsxandcredentials.jsonexist - Check file paths in settings.yaml
- Ensure
-
Google API authentication issues:
- Verify credentials.json is valid
- Ensure Google Forms API is enabled
- Check OAuth consent screen configuration
-
"No data found for AC" warnings:
- Verify AC numbers exist in all required sheets
- Check column mappings in settings.yaml
- Ensure data format matches expectations
-
Form generation failures:
- Check Google API quotas and limits
- Verify network connectivity
- Review error logs for specific issues
Since all code is in a single main.py file, you can easily:
- Add new questions: Edit the form generation section
- Change data sources: Update Excel column mappings in ConfigLoader
- Modify validation: Update DataValidator class
- Change form structure: Edit FormGenerator methods
The consolidated structure makes it easy to understand and modify the entire workflow.
Google Forms API has the following limits:
- 300 requests per minute per project
- 30,000 requests per day per project
- Form item limits apply
The agent includes retry logic and rate limiting to handle these constraints.
- Credentials: Never commit
credentials.jsonto version control - Data Privacy: Ensure Excel data doesn't contain sensitive information
- Access Control: Review form sharing settings after generation
- Logging: Log files may contain survey data - handle appropriately
Modify logging level in main.py (line ~552):
logger = setup_logging("DEBUG")The consolidated script includes all components in one file:
- ConfigLoader (handles YAML and settings)
- ExcelProcessor (extracts data from Excel)
- FormGenerator (creates Google Forms)
- DataValidator (validates all data)
All classes are accessible within main.py for testing and debugging.
- Fork the repository
- Create a feature branch
- Make your changes to
main.py - Test thoroughly with your data
- Submit a pull request
This project is licensed under the MIT License.
For issues and questions:
- Check the troubleshooting section
- Review
political_survey_agent.logfor error details - Ensure all prerequisites are met (credentials.json, assam.xlsx, settings.yaml)
- Create an issue with detailed error information
-
v2.0.0: Consolidated single-file version
- All code in one
main.pyfile - Simplified structure with 7 essential files
- Interactive command-line interface
- Bengali language support
- Streamlined deployment
- All code in one
-
v1.0.0: Initial release
- Excel data extraction
- Google Forms generation
- Bilingual support
- AC-specific sections
- Comprehensive validation