dialect-map / scripts /check_sheet_names.py
Kakashi75's picture
Modified and added automation
a25ac93
#!/usr/bin/env python3
"""
Check Sheet Names
Quick utility to list all sheet tab names from Google Sheets
"""
import json
from pathlib import Path
from google.oauth2 import service_account
from googleapiclient.discovery import build
# Paths
BASE_DIR = Path(__file__).parent.parent
CONFIG_FILE = BASE_DIR / "config.json"
CREDS_FILE = BASE_DIR / "credentials.json"
def get_sheet_names(spreadsheet_id, service):
"""Get all sheet names from a spreadsheet"""
try:
sheet_metadata = service.spreadsheets().get(spreadsheetId=spreadsheet_id).execute()
sheets = sheet_metadata.get('sheets', [])
return [sheet['properties']['title'] for sheet in sheets]
except Exception as e:
print(f"❌ Error: {e}")
return []
def main():
# Load config
with open(CONFIG_FILE, 'r') as f:
config = json.load(f)
# Authenticate
print("πŸ” Authenticating with Google Sheets API...\n")
credentials = service_account.Credentials.from_service_account_file(
CREDS_FILE,
scopes=['https://www.googleapis.com/auth/spreadsheets.readonly']
)
service = build('sheets', 'v4', credentials=credentials)
# Check each spreadsheet
for sheet_config in config['google_sheets']['spreadsheets']:
name = sheet_config['name']
spreadsheet_id = sheet_config['spreadsheet_id']
print(f"πŸ“Š {name}")
print(f" ID: {spreadsheet_id[:20]}...")
sheet_names = get_sheet_names(spreadsheet_id, service)
if sheet_names:
print(f" βœ… Found {len(sheet_names)} tab(s):")
for tab_name in sheet_names:
print(f" - '{tab_name}'")
else:
print(" ❌ No tabs found or error occurred")
print()
if __name__ == "__main__":
main()