class PublishController(object): def __init__(self): self.conn = Connection() self.printers = self.conn.getPrinters() self.check_printer_status() self.job_id = None def check_printer_status(self): is_selphy = [] for printer in self.printers: is_selphy.append(printer == CONST["PRINTER_NAME"]) if any(is_selphy): print("printer {} is available.".format(CONST["PRINTER_NAME"])) return True else: print("Printer {} is missing.".format(CONST["PRINTER_NAME"])) return False def start_print(self): self.conn.enablePrinter(CONST["PRINTER_NAME"]) self.job_id = self.conn.printFile( CONST["PRINTER_NAME"], "ramdisk/polaroid.jpg", "{event}-{date}".format( event=CONST["EVENT_NAME"], date=datetime.now().strftime("%Y%m%d_%H-%M")), {}, ) self.save_image() def check_print_done(self): if self.conn.getJobs().get(self.job_id, None) is not None: print("Still printing...") return False return True def save_image(self): filepath = "events/{event_name}/{date_time}.jpg".format( event_name=CONST["EVENT_NAME"], date_time=format_time(datetime.now(), True)) """ create folder """ if not os.path.exists(os.path.dirname(filepath)): try: os.makedirs(os.path.dirname(filepath)) except OSError as exc: # Guard against race condition if exc.errno != errno.EEXIST: raise image = Image.open("ramdisk/polaroid.jpg") image.save(filepath)
#getopt //tnxs jacopogh try: params = getopt.getopt(argv[1:],'h') except getopt.GetoptError: print 'Wrong parameter' Usage() #help mode (-h) if "-h" in str(params[0]): Usage() #get today t_today = datetime.today() #our connection conn = Connection() jobs_id = conn.getJobs("all",True).keys() if len(jobs_id) == 0 : print print "non hai stampato alcuna pagina questo mese" print exit(0) #get job attributes jobs_attr = [] for i in jobs_id : jobs_attr.append( conn.getJobAttributes(i)) #get printers printers = conn.getPrinters()
try: params = getopt.getopt(argv[1:], 'h') except getopt.GetoptError: print 'Wrong parameter' Usage() #help mode (-h) if "-h" in str(params[0]): Usage() #get today t_today = datetime.today() #our connection conn = Connection() jobs_id = conn.getJobs("all", True).keys() if len(jobs_id) == 0: print print "non hai stampato alcuna pagina questo mese" print exit(0) #get job attributes jobs_attr = [] for i in jobs_id: jobs_attr.append(conn.getJobAttributes(i)) #get printers printers = conn.getPrinters()