-
Notifications
You must be signed in to change notification settings - Fork 0
/
prova.py
54 lines (44 loc) · 1.55 KB
/
prova.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import win32print
import time
PRINTER_ERROR_STATES = (
win32print.PRINTER_STATUS_NO_TONER,
win32print.PRINTER_STATUS_NOT_AVAILABLE,
win32print.PRINTER_STATUS_OFFLINE,
win32print.PRINTER_STATUS_OUT_OF_MEMORY,
win32print.PRINTER_STATUS_OUTPUT_BIN_FULL,
win32print.PRINTER_STATUS_PAGE_PUNT,
win32print.PRINTER_STATUS_PAPER_JAM,
win32print.PRINTER_STATUS_PAPER_OUT,
win32print.PRINTER_STATUS_PAPER_PROBLEM,
)
def printer_errorneous_state(printer, error_states=PRINTER_ERROR_STATES):
prn_opts = win32print.GetPrinter(printer)
status_opts = prn_opts[18]
for error_state in error_states:
if status_opts & error_state:
return error_state
return 0
def printCatching(printJob):
for key,values in printJob.items():
if str(key)=="Status" & str(values)=="None":
print(str(key)+" ==> value ==> "+str(values))
pass
def main():
printer_name=win32print.GetDefaultPrinter()
while 1:
time.sleep(1)
prn = win32print.OpenPrinter(printer_name)
error = printer_errorneous_state(prn)
if error:
print("ERROR occurred: ", error)
else:
print("Printer OK... Name of Printer :" + prn)
ilist = win32print.GetJob(prn, jobID, 1)
print_jobs = win32print.EnumJobs(prn, 0, 1, 2)
currentJob={}
for job in print_jobs:
while(win32print.GetJob(job["JobId"])>0):
currentJob=job
printCatching(currentJob)
if __name__ == "__main__":
main()