This Qiita article is a memo of the code used in the YouTube video. ▼ Please check the video for details (I'm really happy if you like the YouTube video) https://youtu.be/TpkL5hQDPWo
First, create a new project on the http://console.developers.google.com/ page and enable the following two APIs.
Then type two commands in the terminal.
$ pip install gspread
$ pip install oauth2client
sample.py
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from pprint import pprint
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope)
client = gspread.authorize(creds)
#I'm getting the first sheet titled python.
sheet = client.open("python").sheet1
#All values are assigned to a variable called data.
data = sheet.get_all_records()
#Vertical and horizontal data can be obtained by the following methods.
row = sheet.row_values(3)
col = sheet.col_values(3)
#If you want to get only a specific cell, you can get it below.
cell = sheet.cell(3,2).value
#If you want to change or add values to your spreadsheet, you can do the following:
sheet.update_cell(3,2, "nakajo")
insertRow = [3, "nakajo", "Tangerine juice"]
sheet.insert_row(insertRow, 3)
pprint(data)
$ python sample.py
http://youtube.com/user/NJTVnetwork?sub_confirmation=1 We are aiming for ** 1,000 subscribers **!
Recommended Posts