import sqlite3
import random

DB_PATH = "/var/www/AdoptionELS_DB.db"

def main():
    try:
        conn = sqlite3.connect(DB_PATH)
        c = conn.cursor()

        # Update all rows in tec with different random values
        c.execute("SELECT rowid FROM tec")
        tec_rows = c.fetchall()
        for row in tec_rows:
            rowid = row[0]
            new_val = random.randint(50, 100)
            state = 1 if new_val < 60 else 0
            c.execute("UPDATE tec SET get_TEC_current = ?, state = ? WHERE rowid = ?", (new_val, state, rowid))

        # Update all rows in mode_map with different random values
        c.execute("SELECT rowid FROM mode_map")
        mode_rows = c.fetchall()
        for row in mode_rows:
            rowid = row[0]
            new_val = random.randint(200, 300)
            state = 1 if new_val < 210 else 0
            c.execute("UPDATE mode_map SET set_wavelength = ?, state = ? WHERE rowid = ?", (new_val, state, rowid))

        conn.commit()
        print("Tec and Controller values updated with random values")
    except Exception as e:
        print(f"Error: {e}")
    finally:
        c.close()
        conn.close()

if __name__ == "__main__":
    main()
