quip下载
Quip is a collaborative productivity software suite for mobile and the Web. It allows groups of people to create and edit documents and spreadsheets as a group, typically for business purposes. (Wikipedia)
Quip是用于移动和Web的协作式生产力软件套件。 它允许一群人创建和编辑文档和电子表格,通常用于商业目的。 ( 维基百科 )
A major difference between Quip and Google Docs/Sheets is that Quip has a native desktop app.
Quip和Google文档/表格之间的主要区别在于Quip具有本地桌面应用程序。
In this post, I will show you how to automate the process of creating, inserting into, and updating a Quip spreadsheet using its Python API client. To enhance the functionalities of the API, I made a fork of its official GitHub repository and incorporated some useful pull requests not yet merged into the master branch. Download quip.py
from my repository to continue with this tutorial.
在本文中,我将向您展示如何使用其Python API客户端自动化创建,插入和更新Quip电子表格的过程。 为了增强API的功能,我对其官方GitHub存储库进行了分叉,并合并了一些尚未合并到master分支中的有用拉取请求。 从我的存储库下载quip.py
,以继续本教程。
Quip API基础 (Quip API basics)
The official API documentation lives on this site. You will need an access token to interact with Quip’s API. Visit the page https://quip.com/dev/token to generate a personal access token.
官方API文档位于该站点上 。 您将需要一个访问令牌才能与Quip的API进行交互。 访问页面https://quip.com/dev/token以生成个人访问令牌。
To open a Python client:
要打开Python客户端:
import quip
ACCESS_TOKEN = "" # your access token
client = quip.QuipClient(access_token=ACCESS_TOKEN)
An entity essential to Quip API is a thread.
Quip API必不可少的实体是线程。
Quip integrates documents and messages into a single unit that we call a thread. Most of the operations in the Quip Automation API operate on threads. Threads can simply be a list of messages, i.e., a chat thread, or they may have a document in addition to a list of messages. (Quip API Doc)
Quip将文档和消息集成到一个我们称为线程的单元中。 Quip Automation API中的大多数操作都在线程上进行。 线程可以简单地是消息列表,即聊天线程,或者除了消息列表之外还可以具有文档。 ( Quip API文件 )
在Quip中创建电子表格 (Creating a spreadsheet in Quip)
Passing in an empty string as the first argument to new_document
tells Quip to use its default HTML template.
传递空字符串作为new_document
的第一个参数,告诉new_document
使用其默认HTML模板。
jso = client.new_document("", title="My Spreadsheet", type="spreadsheet")
You can also specify an HTML string to use as the template in the second snippet. Create a file called template.html as follows. This spreadsheet template consists of only two columns.
您还可以在第二个片段中指定一个HTML字符串作为模板。 如下创建一个名为template.html的文件。 该电子表格模板仅包含两列。
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
</table>with open("template.html", "rt") as f:
template = f.read()
jso = client.new_document(template, title="My Spreadsheet", type="spreadsheet")
Hold onto the thread_id
from the server’s response. We will need this as a reference to our created spreadsheet to insert/update records.
保留服务器响应中的thread_id
。 我们将需要它作为对我们创建的电子表格进行插入/更新记录的参考。
thread_id = jso["thread"]["id"]
Let’s update the headers (A and B by default) to something more descriptive.
让我们将标头(默认情况下为A和B)更新为更具描述性的内容。
client.update_spreadsheet_headers(thread_id, "Name", "Email")
Check that the headers have been set correctly:
检查标题是否已正确设置:
spreadsheet = client.get_first_spreadsheet(thread_id)
headers = client.get_spreadsheet_header_items(spreadsheet)
print(headers) # prints ['Name', 'Email']
按标题检索电子表格 (Retrieving a spreadsheet by title)
title = "My Spreadsheet"
jso = client.get_matching_threads(title, only_match_titles=True)
# get the id of the first thread
thread_id = jso[0]["thread"]["id"]
将记录插入电子表格 (Inserting records into the spreadsheet)
client.add_to_spreadsheet(thread_id, ["John Doe", "jdoe@gmail.com"])
client.add_to_spreadsheet(thread_id, ["Jane Doe", "jane@gmail.com"])
更新电子表格中的记录 (Updating records in the spreadsheet)
Suppose Jane updates her email to be jd12@gmail.com, let’s update the spreadsheet to reflect this change.
假设Jane将她的电子邮件更新为jd12@gmail.com,让我们更新电子表格以反映此更改。
client.update_spreadsheet_row(thread_id, "Name", "Jane Doe", {"Email": "jd12@gmail.com"})
A caveat: Quip’s API implements strict rate limiting, and the default is 50 requests per minute, meaning you can only insert/update up to 50 records per minute. Read more about custom headers like X-Ratelimit-Limit
in the documentation.
注意:Quip的API实现严格的速率限制,默认值为每分钟50个请求,这意味着您每分钟最多只能插入/更新50条记录。 在文档中阅读有关X-Ratelimit-Limit
类的自定义标头的更多信息。
与组织中的其他Quip用户共享电子表格 (Sharing the spreadsheet with other Quip users in your organization)
Suppose you want to share this spreadsheet with your colleague whose email is smith@gmail.com.
假设您想与电子邮件为smith@gmail.com的同事共享此电子表格。
email = "smith@gmail.com"
jso = client.get_user(email)
member_id = jso["id"]
client.add_thread_members(thread_id, [member_id])
Those are the basics of Quip’s spreadsheet API. Thanks for reading!
这些是Quip电子表格API的基础。 谢谢阅读!
翻译自: https://towardsdatascience.com/updating-a-quip-spreadsheet-with-python-api-1b4bb24d4aac
quip下载