一个用于单向同步google电子表格到数据库的小型库

sheet2db的Python项目详细描述


表2DB

sheet2db是一个很小的python库,用于单向同步google电子表格到数据库。(目前只支持MySQL)

它对于管理google电子表格上的一些静态数据很有用,但也希望将工作表数据同步到数据库。

sheet2db不收集任何机密值!

安装

pip install sheet2db

用法

You must have API key which is accessible to Google Spreadsheet API

示例工作表格式(items选项卡):

===========================
|  A |    B |     C |   D |
===========================
| id | name | count | ver |
|----|------|-------|-----|
| .. | .... | ..... | ... |
===========================

下面的示例将把items选项卡的1u3un2zjprhlrwzc2dmxq8vi7nqf9pylajfo4mqvczpe电子表格同步到数据库:

"AIzaSyC6pabjqmaPiguYoHbq4W7a0DV0wQg5JGk" is a fake api key

fromsheet2dbimportSheet2db# Pass API keysyncer=Sheet2db(api_key='AIzaSyC6pabjqmaPiguYoHbq4W7a0DV0wQg5JGk')# If you need to access to private spreadsheet, you can't use API key. Use oauth credentials instead.syncer=Sheet2db(creds_path='credentials.json',token_path='token.json')# Fetch data from spreadsheetsyncer.fetch(sheet='1U3un2ZJPRhLrWzc2DMXq8VI7Nqf9pYlajfO4mQVCZpE',tab='items',range='A1:D')# Sync fetched data to database (mysql)syncer.sync(host='192.168.168.10',port=3306,user='mingrammer',password='p@ssw0rd',db='static',table='items')

您还可以使用ssh隧道访问带有sshtunnel的远程数据库

withsshtunnel.SSHTunnelForwarder(('db.service.io',22),ssh_username='ssh_user'ssh_pkey='~/.ssh/id_rsa'ssh_private_key_password='ssh_pk_password',remote_bind_address=('localhost',3306),)astunnel:syncer.sync(host=tunnel.local_bind_host,port=tunnel.local_bind_host,user='mingrammer',password='p@ssw0rd',db='static',table='items')

许可证

麻省理工学院

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
serversocket Java服务器socket中断如何   java通过随机类和排序为数组生成数据   @Column length大于255个字符的java实体   java在使用NIO2 API时消除检查异常   java使用用户凭据通过Microsoft Graph API上的控制台应用程序发送电子邮件   java将2个ArrayList一个接一个地显示到jTextArea中,根据输入的数据多次显示   java无法使用导入的库。安卓工作室。谷歌云端点jar   spring boot Neo4j Apoc在java中获取结果摘要时的情况   转义特殊字符javajson   无法在java中使用OpenCV读取图像,涉及unicode路径   swing Document Listener java“无法实例化DocumentListener类型”   java Piglatin,难以理解如何移动“.”一串   java映射请求基于一个可观察对象中的每个元素,使用改进?   java在可扩展字符串中搜索时,如何忽略字符的大小写?   在包中分组类的java约定   python为Java应用程序创建Ubuntu指示小程序   java Camunda:如何通过processInstanceId获取所有已完成的任务