From 4ed6e418603fe4d0a3b3d011daafb36b62ae13c7 Mon Sep 17 00:00:00 2001 From: epicgdog <91296067+epicgdog@users.noreply.github.com> Date: Thu, 10 Jul 2025 20:15:23 -0700 Subject: [PATCH 01/11] added over file for testing --- printer/logparser.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 printer/logparser.py diff --git a/printer/logparser.py b/printer/logparser.py new file mode 100644 index 0000000..01ecdc0 --- /dev/null +++ b/printer/logparser.py @@ -0,0 +1,42 @@ +import sqlite3 +import subprocess +import datetime + +try: + + mydb = sqlite3.connect("printer_jobs.db") + mycursor = mydb.cursor() + sql = "CREATE TABLE IF NOT EXISTS entries(date VARCHAR(255), job_id VARCHAR(255), PRIMARY KEY (date, job_id))" + mycursor.execute(sql) + + CMD = "lpstat -o HP_LaserJet_p2015dn_Right" + p = subprocess.Popen(CMD, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + p.wait() + + if p.returncode != 0: + raise subprocess.CalledProcessError(p.returncode, CMD) + + output = p.stdout.read() + cleaned_output = output.strip().split(" ") + job_id = cleaned_output[0] + + output_dt = cleaned_output[:-7:-1] + output_dt_str = " ".join(output_dt[::-1]) + date_obj = datetime.datetime.strptime(output_dt_str, "%a %b %d %H:%M:%S %Y") + date_str = date_obj.strftime("%Y-%m-%d %H:%M:%S") + + sql_insert = "INSERT INTO entries (date, job_id) VALUES (?, ?)" + mycursor.execute(sql_insert, (date_str, job_id)) + mydb.commit() + + # debug, make sure the data is inserted + the date is good. + sql_query = "SELECT * FROM entries" + mycursor.execute(sql_query) + for x in mycursor.fetchall(): + print(x[0]) + print("job id: " + x[1]) + +except Exception as e: + print(f"An error occurred: {e}") + + From d86c6bc300102c22e83d583434c0cccbbb5a9533 Mon Sep 17 00:00:00 2001 From: epicgdog <91296067+epicgdog@users.noreply.github.com> Date: Thu, 10 Jul 2025 20:22:23 -0700 Subject: [PATCH 02/11] changed file name --- printer/{logparser.py => log_saver.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename printer/{logparser.py => log_saver.py} (100%) diff --git a/printer/logparser.py b/printer/log_saver.py similarity index 100% rename from printer/logparser.py rename to printer/log_saver.py From 8e66529c4ec3769e55064c96f8ceaf59113b328e Mon Sep 17 00:00:00 2001 From: epicgdog <91296067+epicgdog@users.noreply.github.com> Date: Thu, 10 Jul 2025 20:42:22 -0700 Subject: [PATCH 03/11] repetitive calling for log_saver --- .gitignore | 1 + printer/log_saver.py | 36 ++++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index c987cb5..f59e1c1 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ config.json venv/ tmp/ +printer/printer_jobs.db diff --git a/printer/log_saver.py b/printer/log_saver.py index 01ecdc0..5905fa6 100644 --- a/printer/log_saver.py +++ b/printer/log_saver.py @@ -1,20 +1,22 @@ import sqlite3 import subprocess import datetime +import time -try: - - mydb = sqlite3.connect("printer_jobs.db") - mycursor = mydb.cursor() - sql = "CREATE TABLE IF NOT EXISTS entries(date VARCHAR(255), job_id VARCHAR(255), PRIMARY KEY (date, job_id))" - mycursor.execute(sql) +LINE_CMD = "echo '-----------'" +QUERY_CMD = "lpstat -o HP_LaserJet_p2015dn_Right" - CMD = "lpstat -o HP_LaserJet_p2015dn_Right" - p = subprocess.Popen(CMD, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) +mydb = sqlite3.connect("printer_jobs.db") +mycursor = mydb.cursor() +sql = "CREATE TABLE IF NOT EXISTS entries(date VARCHAR(255), job_id VARCHAR(255), PRIMARY KEY (date, job_id))" +mycursor.execute(sql) + +def query_printer_jobs(): + p = subprocess.Popen(QUERY_CMD, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) p.wait() if p.returncode != 0: - raise subprocess.CalledProcessError(p.returncode, CMD) + raise subprocess.CalledProcessError(p.returncode, QUERY_CMD) output = p.stdout.read() cleaned_output = output.strip().split(" ") @@ -35,8 +37,18 @@ for x in mycursor.fetchall(): print(x[0]) print("job id: " + x[1]) - -except Exception as e: - print(f"An error occurred: {e}") + +if __name__ == "__main__": + # This will run the query_printer_jobs function every second + # and print the job id and date from the database. + while True: + subprocess.run(LINE_CMD, shell=True) + try: + query_printer_jobs() + except Exception as e: + print(f"An error occurred: {e}") + break + + time.sleep(1) From a2545ecfdf35879135b9a37b98cdfee6cc281526 Mon Sep 17 00:00:00 2001 From: epicgdog <91296067+epicgdog@users.noreply.github.com> Date: Thu, 10 Jul 2025 21:03:35 -0700 Subject: [PATCH 04/11] logging + empty outputs --- printer/log_saver.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/printer/log_saver.py b/printer/log_saver.py index 5905fa6..349e789 100644 --- a/printer/log_saver.py +++ b/printer/log_saver.py @@ -2,10 +2,18 @@ import subprocess import datetime import time +import logging LINE_CMD = "echo '-----------'" QUERY_CMD = "lpstat -o HP_LaserJet_p2015dn_Right" +logging.basicConfig( + # in mondo we trust + format="%(asctime)s.%(msecs)03dZ %(levelname)s:%(name)s:%(message)s", + datefmt="%Y-%m-%dT%H:%M:%S", + level=logging.INFO, +) + mydb = sqlite3.connect("printer_jobs.db") mycursor = mydb.cursor() sql = "CREATE TABLE IF NOT EXISTS entries(date VARCHAR(255), job_id VARCHAR(255), PRIMARY KEY (date, job_id))" @@ -19,6 +27,10 @@ def query_printer_jobs(): raise subprocess.CalledProcessError(p.returncode, QUERY_CMD) output = p.stdout.read() + if len(output) == 0: + logging.info("No printer jobs found.") + return + cleaned_output = output.strip().split(" ") job_id = cleaned_output[0] @@ -35,8 +47,7 @@ def query_printer_jobs(): sql_query = "SELECT * FROM entries" mycursor.execute(sql_query) for x in mycursor.fetchall(): - print(x[0]) - print("job id: " + x[1]) + logging.info(f"Date: {x[0]}, Job ID: {x[1]}") if __name__ == "__main__": # This will run the query_printer_jobs function every second @@ -46,7 +57,7 @@ def query_printer_jobs(): try: query_printer_jobs() except Exception as e: - print(f"An error occurred: {e}") + logging.error(f"Error querying printer jobs: {e}") break time.sleep(1) From e9e2c1011784ef39a7b4e5d139f9e887eec4e5b5 Mon Sep 17 00:00:00 2001 From: epicgdog <91296067+epicgdog@users.noreply.github.com> Date: Thu, 10 Jul 2025 21:09:53 -0700 Subject: [PATCH 05/11] debugging --- printer/log_saver.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/printer/log_saver.py b/printer/log_saver.py index 349e789..0dad589 100644 --- a/printer/log_saver.py +++ b/printer/log_saver.py @@ -28,15 +28,14 @@ def query_printer_jobs(): output = p.stdout.read() if len(output) == 0: - logging.info("No printer jobs found.") return cleaned_output = output.strip().split(" ") job_id = cleaned_output[0] output_dt = cleaned_output[:-7:-1] - output_dt_str = " ".join(output_dt[::-1]) - date_obj = datetime.datetime.strptime(output_dt_str, "%a %b %d %H:%M:%S %Y") + output_dt_str = "".join(output_dt[::-1]) + date_obj = datetime.datetime.strptime(output_dt_str, "%a %b %d %H:%M:%S %Y") date_str = date_obj.strftime("%Y-%m-%d %H:%M:%S") sql_insert = "INSERT INTO entries (date, job_id) VALUES (?, ?)" From 4282cc5e798cdc6ebc8ff348c2284f34ed93a7f3 Mon Sep 17 00:00:00 2001 From: epicgdog <91296067+epicgdog@users.noreply.github.com> Date: Thu, 10 Jul 2025 21:18:49 -0700 Subject: [PATCH 06/11] fixed string parsing --- printer/log_saver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printer/log_saver.py b/printer/log_saver.py index 0dad589..6ca8f3a 100644 --- a/printer/log_saver.py +++ b/printer/log_saver.py @@ -34,7 +34,7 @@ def query_printer_jobs(): job_id = cleaned_output[0] output_dt = cleaned_output[:-7:-1] - output_dt_str = "".join(output_dt[::-1]) + output_dt_str = " ".join(output_dt[::-1]).strip() date_obj = datetime.datetime.strptime(output_dt_str, "%a %b %d %H:%M:%S %Y") date_str = date_obj.strftime("%Y-%m-%d %H:%M:%S") From 9336cb6e8eaadef63a9828430f5849b36d41d6cf Mon Sep 17 00:00:00 2001 From: epicgdog <91296067+epicgdog@users.noreply.github.com> Date: Thu, 10 Jul 2025 21:29:57 -0700 Subject: [PATCH 07/11] one print statement can save the day --- printer/log_saver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printer/log_saver.py b/printer/log_saver.py index 6ca8f3a..1753ac1 100644 --- a/printer/log_saver.py +++ b/printer/log_saver.py @@ -46,7 +46,7 @@ def query_printer_jobs(): sql_query = "SELECT * FROM entries" mycursor.execute(sql_query) for x in mycursor.fetchall(): - logging.info(f"Date: {x[0]}, Job ID: {x[1]}") + print(f"Date: {x[0]}, Job ID: {x[1]}") if __name__ == "__main__": # This will run the query_printer_jobs function every second From b03eb86dd0ecd48cda51abe7cb6de08ffc5ed40a Mon Sep 17 00:00:00 2001 From: epicgdog <91296067+epicgdog@users.noreply.github.com> Date: Thu, 10 Jul 2025 21:36:07 -0700 Subject: [PATCH 08/11] =?UTF-8?q?maybe=203=20logs=20are=20good=20?= =?UTF-8?q?=F0=9F=AA=B5=F0=9F=AA=B5=F0=9F=AA=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- printer/log_saver.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/printer/log_saver.py b/printer/log_saver.py index 1753ac1..0746a77 100644 --- a/printer/log_saver.py +++ b/printer/log_saver.py @@ -29,7 +29,8 @@ def query_printer_jobs(): output = p.stdout.read() if len(output) == 0: return - + + logging.info(output) cleaned_output = output.strip().split(" ") job_id = cleaned_output[0] @@ -37,16 +38,18 @@ def query_printer_jobs(): output_dt_str = " ".join(output_dt[::-1]).strip() date_obj = datetime.datetime.strptime(output_dt_str, "%a %b %d %H:%M:%S %Y") date_str = date_obj.strftime("%Y-%m-%d %H:%M:%S") + logging.info(date_str, job_id) sql_insert = "INSERT INTO entries (date, job_id) VALUES (?, ?)" mycursor.execute(sql_insert, (date_str, job_id)) mydb.commit() + logging.info("inserted into sql db") # debug, make sure the data is inserted + the date is good. sql_query = "SELECT * FROM entries" mycursor.execute(sql_query) for x in mycursor.fetchall(): - print(f"Date: {x[0]}, Job ID: {x[1]}") + logging.info(f"Date: {x[0]}, Job ID: {x[1]}") if __name__ == "__main__": # This will run the query_printer_jobs function every second From d9132f5bc302c2902484aec461f4eb23034984b4 Mon Sep 17 00:00:00 2001 From: epicgdog <91296067+epicgdog@users.noreply.github.com> Date: Mon, 14 Jul 2025 22:02:11 -0700 Subject: [PATCH 09/11] added printer simulator + print status with each entry --- printer/log_saver.py | 88 +++++++++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 21 deletions(-) diff --git a/printer/log_saver.py b/printer/log_saver.py index 0746a77..4d080ae 100644 --- a/printer/log_saver.py +++ b/printer/log_saver.py @@ -3,8 +3,12 @@ import datetime import time import logging +import random +import asyncio -LINE_CMD = "echo '-----------'" +DEBUG = True + +LINE_CMD = "echo -----------" QUERY_CMD = "lpstat -o HP_LaserJet_p2015dn_Right" logging.basicConfig( @@ -16,21 +20,60 @@ mydb = sqlite3.connect("printer_jobs.db") mycursor = mydb.cursor() -sql = "CREATE TABLE IF NOT EXISTS entries(date VARCHAR(255), job_id VARCHAR(255), PRIMARY KEY (date, job_id))" +sql = ''' +CREATE TABLE IF NOT EXISTS entries( + date TEXT NOT NULL DEFAULT "0000-00-00 00:00:00", + job_id TEXT NOT NULL DEFAULT "0000-0000", + p_status TEXT CHECK (p_status IN ('PRINTING', 'PENDING', 'COMPLETED', 'FAILED')) NOT NULL DEFAULT "PRINTING", + PRIMARY KEY (date, job_id) +)''' mycursor.execute(sql) -def query_printer_jobs(): - p = subprocess.Popen(QUERY_CMD, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) +def print_db(): + sql_query = "SELECT * FROM entries" + mycursor.execute(sql_query) + for x in mycursor.fetchall(): + logging.info(x) + +def test_job_ids(): + x = random.randint(3, 7) + MOCK_CMD = f"echo HP_LaserJet_p2015dn_Right-{x} root 5120 Mon Jul 7 03:43:42 2025" + DONE_CMD = "" + for n in range(x): + query_printer_jobs(MOCK_CMD) + time.sleep(1) + query_printer_jobs(DONE_CMD) + +def simulate_printer_jobs(): + + test_job_ids() + time.sleep(0.5) + + + test_job_ids() +def query_printer_jobs(cmd): + p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) p.wait() if p.returncode != 0: - raise subprocess.CalledProcessError(p.returncode, QUERY_CMD) + raise subprocess.CalledProcessError(p.returncode, cmd) output = p.stdout.read() if len(output) == 0: + # set everything to completed + sql_update_completed = ''' + UPDATE entries SET p_status = 'COMPLETED' WHERE p_status = 'PRINTING' + ''' + mycursor.execute(sql_update_completed) + mydb.commit() + logging.info("No jobs found, updated all to COMPLETED") + + if DEBUG: + print_db() return + - logging.info(output) + #logging.info(output) cleaned_output = output.strip().split(" ") job_id = cleaned_output[0] @@ -38,30 +81,33 @@ def query_printer_jobs(): output_dt_str = " ".join(output_dt[::-1]).strip() date_obj = datetime.datetime.strptime(output_dt_str, "%a %b %d %H:%M:%S %Y") date_str = date_obj.strftime("%Y-%m-%d %H:%M:%S") - logging.info(date_str, job_id) + #logging.info(date_str + " " + job_id) - sql_insert = "INSERT INTO entries (date, job_id) VALUES (?, ?)" + sql_insert = ''' + INSERT INTO entries (date, job_id) VALUES (?, ?) + ON CONFLICT(date, job_id) DO UPDATE SET p_status = 'PRINTING' + ''' mycursor.execute(sql_insert, (date_str, job_id)) mydb.commit() - logging.info("inserted into sql db") # debug, make sure the data is inserted + the date is good. - sql_query = "SELECT * FROM entries" - mycursor.execute(sql_query) - for x in mycursor.fetchall(): - logging.info(f"Date: {x[0]}, Job ID: {x[1]}") + if DEBUG: + print_db() if __name__ == "__main__": # This will run the query_printer_jobs function every second # and print the job id and date from the database. - while True: - subprocess.run(LINE_CMD, shell=True) - try: - query_printer_jobs() - except Exception as e: - logging.error(f"Error querying printer jobs: {e}") - break + if DEBUG: + simulate_printer_jobs() + else: + while True: + subprocess.run(LINE_CMD, shell=True) + try: + query_printer_jobs(QUERY_CMD) + except Exception as e: + logging.error(f"Error querying printer jobs: {e}") + break - time.sleep(1) + time.sleep(1) From 97d668c6f4b8af57115dd1ade1f8b8a82abaa293 Mon Sep 17 00:00:00 2001 From: epicgdog <91296067+epicgdog@users.noreply.github.com> Date: Tue, 15 Jul 2025 12:07:39 -0700 Subject: [PATCH 10/11] dynamic date in echo command --- printer/log_saver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printer/log_saver.py b/printer/log_saver.py index 4d080ae..31f407d 100644 --- a/printer/log_saver.py +++ b/printer/log_saver.py @@ -37,7 +37,7 @@ def print_db(): def test_job_ids(): x = random.randint(3, 7) - MOCK_CMD = f"echo HP_LaserJet_p2015dn_Right-{x} root 5120 Mon Jul 7 03:43:42 2025" + MOCK_CMD = f"echo HP_LaserJet_p2015dn_Right-{x} root 5120 {datetime.datetime.now().strftime('%a %b %d %H:%M:%S %Y')}" DONE_CMD = "" for n in range(x): query_printer_jobs(MOCK_CMD) From e4b088b614f39277630acbeeff05ea868e34f8e5 Mon Sep 17 00:00:00 2001 From: epicgdog <91296067+epicgdog@users.noreply.github.com> Date: Mon, 21 Jul 2025 20:56:06 -0700 Subject: [PATCH 11/11] save --- printer/log_saver.py | 139 +++++++++++++++++++++++++++---------------- 1 file changed, 87 insertions(+), 52 deletions(-) diff --git a/printer/log_saver.py b/printer/log_saver.py index 31f407d..2369322 100644 --- a/printer/log_saver.py +++ b/printer/log_saver.py @@ -4,12 +4,12 @@ import time import logging import random -import asyncio +from dataclasses import dataclass -DEBUG = True - -LINE_CMD = "echo -----------" -QUERY_CMD = "lpstat -o HP_LaserJet_p2015dn_Right" +@dataclass +class PrinterJob: + timestamp: str + job_id: str logging.basicConfig( # in mondo we trust @@ -18,82 +18,119 @@ level=logging.INFO, ) +DEBUG = True +QUERY_CMD = "lpstat -o HP_LaserJet_p2015dn_Right" +running_print_jobs = set() mydb = sqlite3.connect("printer_jobs.db") mycursor = mydb.cursor() sql = ''' CREATE TABLE IF NOT EXISTS entries( - date TEXT NOT NULL DEFAULT "0000-00-00 00:00:00", - job_id TEXT NOT NULL DEFAULT "0000-0000", - p_status TEXT CHECK (p_status IN ('PRINTING', 'PENDING', 'COMPLETED', 'FAILED')) NOT NULL DEFAULT "PRINTING", + date TEXT NOT NULL, + job_id TEXT NOT NULL, + p_status TEXT CHECK (p_status IN ('PRINTING', 'PENDING', 'COMPLETED', 'FAILED')) NOT NULL, PRIMARY KEY (date, job_id) )''' mycursor.execute(sql) + def print_db(): sql_query = "SELECT * FROM entries" mycursor.execute(sql_query) for x in mycursor.fetchall(): logging.info(x) -def test_job_ids(): - x = random.randint(3, 7) - MOCK_CMD = f"echo HP_LaserJet_p2015dn_Right-{x} root 5120 {datetime.datetime.now().strftime('%a %b %d %H:%M:%S %Y')}" - DONE_CMD = "" - for n in range(x): - query_printer_jobs(MOCK_CMD) - time.sleep(1) - query_printer_jobs(DONE_CMD) - -def simulate_printer_jobs(): +def get_time_and_id(line): + cleaned_output = line.strip().split(" ") + job_id = cleaned_output[0] - test_job_ids() - time.sleep(0.5) - + output_dt = cleaned_output[:-7:-1] + output_dt_str = " ".join(output_dt[::-1]).strip() + date_obj = datetime.datetime.strptime(output_dt_str, "%a %b %d %H:%M:%S %Y") + date_str = date_obj.strftime("%Y-%m-%d %H:%M:%S") + return PrinterJob(timestamp=date_str, job_id=job_id) - test_job_ids() -def query_printer_jobs(cmd): +def call_lpstat_popen(cmd): p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) p.wait() if p.returncode != 0: raise subprocess.CalledProcessError(p.returncode, cmd) - output = p.stdout.read() + output = p.stdout.read().strip() if len(output) == 0: - # set everything to completed - sql_update_completed = ''' - UPDATE entries SET p_status = 'COMPLETED' WHERE p_status = 'PRINTING' + return None + + # 2 things at once; add new jobs to new one while also retrieving current job_ids + return output.split("\n") + +def update_completed_jobs(current_jobs): + global running_print_jobs + + # everything in the previous run that IS NOT in the current run + completed_jobs = running_print_jobs.difference(current_jobs) + for job_id in completed_jobs: + sql_update = ''' + UPDATE entries SET p_status = 'COMPLETED' WHERE job_id = ? ''' - mycursor.execute(sql_update_completed) + mycursor.execute(sql_update, job_id) mydb.commit() - logging.info("No jobs found, updated all to COMPLETED") - if DEBUG: - print_db() - return + logging.info(f"\nthis is the running jobs {running_print_jobs}\nand this is the current jobs {current_jobs}") + running_print_jobs.update(running_print_jobs - completed_jobs) - - #logging.info(output) - cleaned_output = output.strip().split(" ") - job_id = cleaned_output[0] - - output_dt = cleaned_output[:-7:-1] - output_dt_str = " ".join(output_dt[::-1]).strip() - date_obj = datetime.datetime.strptime(output_dt_str, "%a %b %d %H:%M:%S %Y") - date_str = date_obj.strftime("%Y-%m-%d %H:%M:%S") + + + +def query_printer_jobs(cmd): #logging.info(date_str + " " + job_id) + jobs = call_lpstat_popen(cmd) + current_jobs = set() + if not jobs: + # that means we are done in some way + # TODO: should i add code here to remove everything in sqlite database since no jobs? + update_completed_jobs(current_jobs) + return + + global running_print_jobs + + for job in jobs: + print_job_dataclass = get_time_and_id(job) + job_id = print_job_dataclass.job_id + timestamp = print_job_dataclass.timestamp + + current_jobs.add(job_id) + + if job_id in running_print_jobs: + continue + + running_print_jobs.add(job_id) + sql_insert = ''' + INSERT INTO entries (date, job_id, p_status) VALUES (?, ?, 'PRINTING') + ''' + mycursor.execute(sql_insert, (timestamp, job_id)) + mydb.commit() + + update_completed_jobs(current_jobs) + - sql_insert = ''' - INSERT INTO entries (date, job_id) VALUES (?, ?) - ON CONFLICT(date, job_id) DO UPDATE SET p_status = 'PRINTING' - ''' - mycursor.execute(sql_insert, (date_str, job_id)) - mydb.commit() - - # debug, make sure the data is inserted + the date is good. if DEBUG: print_db() +def test_job_ids(): + x = random.randint(1,1) + MOCK_CMD = f"echo HP_LaserJet_p2015dn_Right-{x} root 5120 {datetime.datetime.now().strftime('%a %b %d %H:%M:%S %Y')}" + DONE_CMD = "" + for n in range(x): + query_printer_jobs(MOCK_CMD) + time.sleep(1) + query_printer_jobs(DONE_CMD) + +def simulate_printer_jobs(): + + test_job_ids() + # time.sleep(0.5) + # test_job_ids() + if __name__ == "__main__": # This will run the query_printer_jobs function every second # and print the job id and date from the database. @@ -101,13 +138,11 @@ def query_printer_jobs(cmd): simulate_printer_jobs() else: while True: - subprocess.run(LINE_CMD, shell=True) try: query_printer_jobs(QUERY_CMD) + time.sleep(1) except Exception as e: logging.error(f"Error querying printer jobs: {e}") break - time.sleep(1) -