一个用于单向同步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')
许可证
麻省理工学院