선릉역 1번 출구
google spreadsheet python 연동하기 본문
1. https://console.cloud.google.com/ 접속
2. google drive api, google sheet api 다운로드 하기
3. 사용자 인증 정보
서비스 계정 만들기
위의 필드 모두 채워넣기
4. 작업에 눌러서 만든 서비스계정에 키 부여 받기 (json 파일로 저장하면 됨)
1~4에 해당하는 절차는 https://hleecaster.com/python-google-drive-spreadsheet-api/ 참고
5. 접근하고 싶은 해당 스프레드시트 접속 후
사용자 및 그룹 추가에 아까 만든 서비스 계정 이메일 넣기
6. vsCode나 각자 자기가 사용하는 에디터 들어가서 터미널 접속
pip install gspread
pip install --upgrade oauth2client
명령어 사용해서 필요한 것들 설치
7. 해당 코드에 필요한 내용 작성
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = [
'https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive',
]
json_file_name = 'json 파일명'
credentials = ServiceAccountCredentials.from_json_keyfile_name(json_file_name, scope)
gc = gspread.authorize(credentials)
spreadsheet_url = '스프레드 시트 주소'
# 스프레스시트 문서 가져오기
doc = gc.open_by_url(spreadsheet_url)
# 시트 선택하기
worksheet = doc.worksheet('시트 이름')
여기에 맞게 작성
8. 특정 셀 가져오기
cell_data = worksheet.acell('특정 열').value
print(cell_data)
출력이 완료되면 끝
'Project' 카테고리의 다른 글
infra 구축(apache, tomcat, mysql, rsyslog) (2) | 2023.02.09 |
---|---|
[침해사고 분석] (0) | 2022.11.29 |
mini_project using Mediapipe(5) (0) | 2021.11.29 |
mini_project using Mediapipe(4) (0) | 2021.11.28 |
mini_project using Mediapipe(3) (0) | 2021.11.27 |
Comments