Make the MySQL table name configurable instead of hardcoding TempHumid.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-16 11:44:18 +08:00
co-authored by Cursor
parent 8010cd9045
commit 2d1e319160
7 changed files with 31 additions and 10 deletions
+4 -4
View File
@@ -7,18 +7,18 @@ import time
import MySQLdb
def main(temp, humid, host, db, user, passwd, logging, sql_retries, sql_timeout):
def main(temp, humid, host, db, table, user, passwd, logging, sql_retries, sql_timeout):
logging.debug('Temp = %s *C, Hum = %s %%', temp, humid)
logging.debug('Updating MySQL database next ...')
sql = (
'INSERT INTO TempHumid (ComputerTime, Temperature, Humidity, id) '
f'INSERT INTO `{table}` (ComputerTime, Temperature, Humidity, id) '
'VALUES (unix_timestamp(now()), %s, %s, NULL)'
)
args = (format(temp, '5.1f'), format(humid, '5.1f'))
logging.info(
'Temperature: %s*C Humidity: %s%% ... updating to MySQL database',
args[0], args[1],
'Temperature: %s*C Humidity: %s%% ... updating MySQL table %s',
args[0], args[1], table,
)
for attempt in range(sql_retries):