-
-
Save illucent/ff73f7e7026bd3a0a8c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import sys | |
from os import listdir | |
from os.path import isfile, join | |
from time import sleep | |
class PrintDaemon: | |
def __init__(self, folder_to_scan = None): | |
if folder_to_scan is not None: | |
self.folder_to_scan = folder_to_scan | |
self.file_list = [ f for f in listdir(self.folder_to_scan) if isfile(join(self.folder_to_scan,f)) ] | |
for file in self.file_list: | |
print "Ignoring %s..." % file | |
def diff(self, a, b): | |
return list(set(a) - set(b)) | |
def printFromFolder(self): | |
while True: | |
updated_file_list = [ f for f in listdir(self.folder_to_scan) if isfile(join(self.folder_to_scan,f)) ] | |
new_items = self.diff(updated_file_list, self.file_list) | |
for item in new_items: | |
print "Printing %s..." % item | |
os.system('convert %s %s +append /tmp/%s' % (item, item, item)) | |
os.system('lpr -o media="4x6" /tmp/%s' % item) | |
self.file_list = updated_file_list | |
sleep(1) | |
if __name__ == '__main__': | |
folder_to_scan = None | |
if len(sys.argv) == 2: | |
folder_to_scan = sys.argv[1] | |
print_daemon = PrintDaemon(folder_to_scan) | |
print_daemon.printFromFolder() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment