I have a question regarding Python gspread + pymyql.

Asked 1 years ago, Updated 1 years ago, 108 views

Hello, everyone After accessing the DB using pymysql, I sent a query and found the result value I would like to update the Google spreadsheet through gspread.

Currently, I can access the spreadsheet through the code below and get the query results, so how can I update the data on the spreadsheet?

Please help me because the amount of results obtained through the query is different every time.

from oauth2client.service_account import ServiceAccountCredentials
import gspread
import pymysql

json = 'C:\\Users\\Jung\\myjson.json'
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name(json, scope)
gc = gspread.authorize(credentials)

wks = gc.open_by_key('18PRjUgS1PkRlPwy2349sdf30OBjGyAXvJX_EKqIkZpS8')
wk0 = wks.worksheet ("test sheet")

connection = pymysql.connect(
        host = "123.123.123.123",  # DATABASE_HOST
        port = 12345,
        user = "testuser",  # DATABASE_USERNAME
        passwd = "testpassword",  # DATABASE_PASSWORD
        db = "testtable2",  # DATABASE_NAME
        charset='utf8'
)
cursor = connection.cursor()
query = ''' SELECT TYPE,amount FROM tbl_testtable WHERE category = 1 AND writedate BETWEEN "2018-07-19 00:00:00" AND "2018-07-19 23:59:59"'''
number_of_rows = cursor.execute(query)
rows = cursor.fetchall()

gspread python pymysql

2022-09-22 17:57

1 Answers

Document says to send a HTTP POST request through API. I think you can write CURL or anything and make a query list and send a request.


2022-09-22 17:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.