I am trying to continuously log whatever a specific value (stock) in my database is at all times, the value is changed 20 times per second (confirmed by looking at results manually)
Yet for some reason, this code here, once it is started, always prints the same output and doesnt change. What am I doing wrong?
import mysql.connector
import keyboard
from time import sleep
connection = mysql.connector.connect(host='localhost',
database='minecraft',
user='root',
password='password')
sql_select_Query = "select stock from xdata where id = \"1\""
file = open("mysqldump.txt", "a")
print("Connection started")
while 1:
cursor = connection.cursor()
cursor.execute(sql_select_Query)
records = cursor.fetchone()[0]
print(records)
file.write(str(records) + "\n")
if(keyboard.is_pressed("x")):
break
sleep(0.1)
print("Connection stopped")
file.close()
connection.close()