File size: 1,849 Bytes
b08d8a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/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()