我正在尝试pygsheets
在ScrapingHub的脚本中使用。pygsheets
脚本的一部分开始于:
google_client = pygsheets.authorize(service_file=CREDENTIALS_FILENAME, no_cache=True)
spreadsheet = google_client.open_by_key(SHEET_ID)
Run Code Online (Sandbox Code Playgroud)
CREDENTIALS_FILENAME
我的Google服务帐户凭据文件名在哪里SHEET_ID
,电子表格ID 在哪里?在某些时候,这正在发生:
2018-01-30 16:27:36 INFO [stdout] service_email : *******@**********.iam.gserviceaccount.com
2018-01-30 16:27:36 INFO [googleapiclient.discovery] URL being requested: GET https://www.googleapis.com/drive/v3/files?corpora=user&pageSize=500&fields=files%28id%2C+name%29&q=mimeType%3D%27application%2Fvnd.google-apps.spreadsheet%27&supportsTeamDrives=false&includeTeamDriveItems=false&alt=json
2018-01-30 16:27:36 INFO [oauth2client.transport] Attempting refresh to obtain initial access_token
2018-01-30 16:27:36 INFO [oauth2client.client] Refreshing access_token
2018-01-30 16:31:50 ERROR [root] Job runtime exception
Traceback (most recent call last):
File "/app/python/lib/python3.6/site-packages/httplib2/__init__.py", line 995, in _conn_request
conn.connect()
File "/usr/local/lib/python3.6/http/client.py", line 1392, in connect
super().connect()
File "/usr/local/lib/python3.6/http/client.py", line 936, in …
Run Code Online (Sandbox Code Playgroud) python google-sheets scrapinghub google-sheets-api pygsheets
我正在寻找一种方法来从Python中的Google工作表中读取单元格的格式,特别是它的背景颜色。
我发现能够读取工作表的两个流行软件包是gspread (fork)和pygsheets。我尝试了两者,它们在读取我的工作表数据方面效果很好,但是从我看来,两者都不支持读取单元格格式,只支持设置它们。pygsheets 的 GitHub 页面上的这个开放问题描述了我需要的功能类型。
本质上,每行都是一个包含时间戳、用户名、注释等的记录,我想查找特定用户名的所有行,并且只查找那些没有红色背景的行,有点像这样:
if ("Username" in record.values()) and (matching_cells.background != red):
# Do something
Run Code Online (Sandbox Code Playgroud)
谢谢!
您好,我计划部署一个可以记录到电子表格的应用程序。我使用了PyGSheets。
我得到加薪。
raise SpreadsheetNotFound('Could not find a spreadsheet with title %s.' % title)
pygsheets.exceptions.SpreadsheetNotFound: Could not find a spreadsheet with title RSSI Spreadsheet.
Run Code Online (Sandbox Code Playgroud)
在我使用 service_account_file 进行授权之后
gc = pygsheets.authorize(service_account_file='something.json')
Run Code Online (Sandbox Code Playgroud)
但它适用于
gc = pygsheets.authorize(client_secret='client_secret_something.json')
Run Code Online (Sandbox Code Playgroud)
我想使用 service_account_file 以便它能够通过授权过程。
我想使用 PyGSheets 在我的 Google Drive 文件夹中创建电子表格。我还希望能够设置使用代码创建工作表的目录/文件夹。具体来说,我想输入一个类似于 URL 的字符串,甚至只是文件夹的名称。
我已经查看了 PyGSheets 文档和“电子表格”模型。我还没有找到任何接受文件夹名称或目录地址的类。也没有用于将工作表从一个文件夹移动到另一个文件夹的类。使用 PyGSheets 可以进行任一操作吗?
shtTargetedCreate = con.create("Test Folder",folder="1GwA4W8iv-26BvG48nKnEigYqDL8SpUGK")
Run Code Online (Sandbox Code Playgroud)
有没有更有效的方法来做到这一点?
我已经可以使用 open_by_key() 函数编辑现有工作表,但我希望能够创建一个全新的工作表。
当我尝试以下代码时:
import pygsheets
creds_file = "/Users/jerome/audible2googlesheet.json"
gc = pygsheets.authorize(service_file=creds_file)
sh = gc.open("my_1st_public_sheet")
wks = sh.sheet1
# Update a single cell.
wks.update_value('A1', "some value")
sh.share('', role='reader', type='anyone')
Run Code Online (Sandbox Code Playgroud)
我收到此异常/错误:
raise SpreadsheetNotFound('无法找到标题为 %s 的电子表格。' % title) pygsheets.exceptions.SpreadsheetNotFound:无法找到标题为 my_1st_public_sheet 的电子表格。
我缺少什么?