0% found this document useful (0 votes)
9 views1 page

Import Gspread

Uploaded by

Ashok Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Import Gspread

Uploaded by

Ashok Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import gspread

from oauth2client.service_account import ServiceAccountCredentials

# Define the scope for accessing Google Sheets


scope = ['https://www.googleapis.com/auth/spreadsheets']

def read_google_sheet(sheet_url, credentials_file):


# Authenticate with Google Sheets using service account credentials
creds = ServiceAccountCredentials.from_json_keyfile_name(credentials_file,
scope)
client = gspread.authorize(creds)

# Open the Google Sheet by URL


sheet = client.open_by_url(sheet_url)

# Select the first worksheet


worksheet = sheet.get_worksheet(0)

# Read data from the worksheet


data = worksheet.get_all_values()

return data

def main():
# Google Sheet URL
sheet_url = "1Emhcd8PkIPj15agqTlokJ8OpemZwX2F-d1ooJB6t8uE"

# Path to the Google Sheets API service account credentials JSON file
credentials_file = ""D:\Download\attendance-389414-01e71fbc3744.json""

# Read data from the Google Sheet


sheet_data = read_google_sheet(sheet_url, credentials_file)

# Print the retrieved data


for row in sheet_data:
print(row)

if __name__ == "__main__":
main()

You might also like