A Python script to bulk import CSV files into Google Sheets with support for Korean text and robust error handling.
- Bulk import of CSV files to Google Sheets
- Support for Korean text (UTF-8, CP949 encoding)
- Automatic rate limiting and retry mechanism
- Secure credential handling
- Progress tracking with emoji indicators
- Detailed logging
- Clone the repository:
git clone <your-repo-url>
cd <repo-directory>- Install dependencies:
pip install -r requirements.txt-
Set up Google Sheets API:
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Sheets API and Google Drive API
- Create credentials (OAuth 2.0 Client ID)
- Download the credentials and save as
credentials.jsonin the project directory
-
Configure the script:
- Copy
config.template.pytoconfig.py - Update
TEMPLATE_SPREADSHEET_IDinconfig.pywith your template spreadsheet ID - Adjust other settings in
config.pyif needed
- Copy
-
Place your CSV files in the
csv_filesdirectory -
Run the script:
python sheets_importer.py- Follow the prompts to:
- Authenticate with Google (first time only)
- Enter a name for the new spreadsheet
The script will:
- Create a new spreadsheet
- Import each CSV file into a separate sheet
- Show progress with emoji indicators
- Log all operations to
import_log.txt
Edit config.py to customize:
TEMPLATE_SPREADSHEET_ID: ID of your template spreadsheetMAX_FILE_SIZE_MB: Maximum allowed CSV file sizeREQUEST_DELAY: Delay between API requestsFILE_DELAY: Delay between processing filesMAX_RETRIES: Maximum number of retry attempts
- Sensitive files (
credentials.json,token.pickle,config.py) are automatically excluded from git - Credentials are stored securely with appropriate file permissions
- OAuth 2.0 authentication is used for Google API access
- Console output shows progress with emoji indicators
- Detailed logs are saved to
import_log.txt - Different log levels for different types of messages
- Automatic retry for rate limit errors
- Multiple encoding support for CSV files
- Validation of file sizes and formats
- Detailed error messages and logging