-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsync_sql.py
More file actions
41 lines (32 loc) · 997 Bytes
/
sync_sql.py
File metadata and controls
41 lines (32 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import pymysql
from seatable_api import Base
server_url = 'http://127.0.0.1:8000'
api_token = '48b6a41a0c2e1ee4bf294ed42445914025a0a60c'
def sync_mysql():
"""Sync database into the table
"""
# seatable data
base = Base(api_token, server_url)
base.auth()
table_name = 'Table1'
rows = base.list_rows(table_name)
row_keys = [row.get('Name') for row in rows]
# mysql data
host = 'localhost'
user = ''
password = ''
db = 'seatable'
connection = pymysql.connect(host=host, user=user, password=password, db=db)
with connection.cursor(pymysql.cursors.DictCursor) as cursor:
sql = "SELECT * FROM order"
cursor.execute(sql)
mysql_data = cursor.fetchall()
# sync
for item in mysql_data:
if item.get('name') not in row_keys:
row_data = {
'Name': item.get('name'),
}
base.append_row(table_name, row_data)
if __name__ == '__main__':
sync_mysql()