File: //proc/1126/cwd/check_sheets.py
from google.oauth2 import service_account
from googleapiclient.discovery import build
# Path to your JSON key file
SERVICE_ACCOUNT_FILE = 'common/config/google/service-account.json'
SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']
# Spreadsheet ID
SPREADSHEET_ID = '1MsCeMx5M1Qo-Lr_zKunyCf4IkEScK0LvpVMFtWPreDI'
RANGE_NAME = 'Лист1!A:E'
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
service = build('sheets', 'v4', credentials=credentials)
# Робимо запит на values
sheet = service.spreadsheets().values().get(
spreadsheetId=SPREADSHEET_ID,
range=RANGE_NAME
).execute()
values = sheet.get('values', [])
if not values:
print('Немає даних у цьому діапазоні.')
else:
print('Значення:', values[0])