Ejemplo n.º 1
0
def changeColorSpecific():
    """Changes color on a specific printer
    """
    verticalLine()
    puts(colored.cyan("Example - Change color on a specific printer"))
    puts("Available printers: ")
    showPrintersBasic()

    ip_input = prompt.query("Enter printer ip: ")
    try:
        ip = ipaddress.ip_address(ip_input)
        ip = str(ip)

        for printer in printerList.getPrinters():
            if printer.getIp() == ip:
                colors = getColorData()

                if not colors:  #An empty dict is False
                    return

                changeColor(printer, colors['hue'], colors['saturation'],
                            colors['brightness'])
    except ValueError:
        puts(
            colored.yellow(
                "You entered an invalid ip adress. (Format: IPv4Address)"))
Ejemplo n.º 2
0
 def get(self):
     cameraList = list()
     for printer in printerList.getPrinters():
         r = printer.get("api/v1/camera")
         if r:
             camera_link = r.json()
             cameraList.append(camera_link)
     return jsonify(cameraList)
Ejemplo n.º 3
0
    def get(self):
        puts(colored.cyan("Getting system information from printers"))
        systemInfoList = list()
        for printer in printerList.getPrinters():
            r = printer.get("/api/v1/system")
            if r:
                systemInfo = r.json()
                systemInfoList.append(systemInfo)

        return jsonify(systemInfoList)
Ejemplo n.º 4
0
    def get(self):
        '''
        parser = reqparse.RequestParser()
        parser.add_argument('printer', type=int)
        args = parser.parse_args()
        print("parser: ")
        print(args)
        '''
        
        images = cache.get("images")
        if images is None:
            imageLinks = list()
            for printer in printerList.getPrinters():
                imageLink = "http://" + printer.getIp() + ":8080/?action=snapshot.jpg"
                imageLinks.append(imageLink)
            #long timeout, the links should not update....
            cache.set("images", imageLinks, timeout=60*60)
            images = cache.get("images")
        

        parser = reqparse.RequestParser()
        parser.add_argument('printer', type=int, required=True)
        args = parser.parse_args()
        printer_numb = args["printer"]

        if printer_numb not in range(0, len(printerList.getPrinters())): 
            msg = jsonify({
                "printer": "Only a ID between 0 and " + str(len(printerList.getPrinters()) - 1) + " is valid"
            })
            return msg

        img_data = requests.get(images[printer_numb]).content

        for i, printer in enumerate(printerList.getPrinters()):
            if i == printer_numb:
                printer_name = printer.getName()

        filePath = "images/"  + printer_name + "_snapshot.jpg"
        with open(filePath, 'wb') as handler:
            handler.write(img_data)

        return send_file(filePath)
Ejemplo n.º 5
0
def changeColorAll():
    """Changes color on all printers
    """
    verticalLine()
    puts(colored.cyan("Example - Change color on all printers"))
    colors = getColorData()

    if not colors:  #An empty dict is False
        return

    for printer in printerList.getPrinters():
        changeColor(printer, colors['hue'], colors['saturation'],
                    colors['brightness'])
Ejemplo n.º 6
0
def showPrinters():
    """Prints a vetical line followed by all printers and all their info.
    """
    verticalLine()
    puts(colored.magenta("Printers"))
    sortedPrinters = sorted(printerList.getPrinters(), key=lambda k: k.getName())

    for printer in sortedPrinters:
        puts(colored.cyan(printer.getName()))
        with indent(4):
            puts("IP-address: " + printer.getIp())
            puts("ID: " + printer.getId())
            puts("Key: " + printer.getKey())
Ejemplo n.º 7
0
 def get(self):
     printJobs = cache.get("printJobs")
     if printJobs is None:
         puts(colored.cyan("Getting current print jobs"))
         printJobList = list()
         for printer in printerList.getPrinters():
             r = printer.get("api/v1/print_job")
             if r:
                 printerJob = r.json()
                 printJobList.append(printerJob)
         cache.set("printJobs", printJobList, timeout=5)
         printJobs = cache.get("printJobs")
     return jsonify(printJobs)
Ejemplo n.º 8
0
    def get(self):
        printerData = cache.get("printerData")
        if printerData is None:
            puts(colored.cyan("Getting new Printer data!"))
            printerDataList = list()
            for printer in printerList.getPrinters():
                r = printer.get("/api/v1/printer")
                if r.status_code == 200:
                    data = r.json()
                    printerDataList.append(data)

            cache.set("printerData", printerDataList, timeout=20)
            printerData = cache.get("printerData")

        return jsonify(printerData)
Ejemplo n.º 9
0
    def get(self):
        history = cache.get("history")
        if history is None:
            puts(colored.cyan("Getting new printer history from all printers, this will take a while!"))
            historyList = list()
            for printer in printerList.getPrinters():
                r = printer.get("/api/v1/history")
                if r.status_code == 200:
                    data = r.json()
                    historyList.append(data)

            #Remove the cache after 30min.
            cache.set("history", historyList, timeout=30*60)
            history = cache.get("history")
        
        return jsonify(history)
Ejemplo n.º 10
0
def duplicateIP(ip):
    """Used for detecting if a printer on the given ip adress already exists.
    
    Arguments:
        ip {string} -- [description]
    
    Returns:
        bool -- True if there exists a printer on the given ip adress, otherwise False
    """

    for printer in printerList.getPrinters():
        if (printer.getIp() == ip):
            puts(
                colored.red(
                    "Printer at ip-address <" + ip +
                    "> already exists. Remove it before adding a new connection."
                ))
            return True
    return False
Ejemplo n.º 11
0
def into():
    return render_template('info.html', printers=printerList.getPrinters())
Ejemplo n.º 12
0
def showPrintersBasic():
    """Prints printer name and ip on one line each
    """
    sortedPrinters = sorted(printerList.getPrinters(), key=lambda k: k.getName())
    for printer in sortedPrinters:
        puts("%s\t%s" % (printer.getName(), printer.getIp()))
Ejemplo n.º 13
0
        self.b = 0


#Create a LED object
led = Led()

verticalLine()
puts(colored.magenta("Status Checker running"))

last_time = datetime.datetime.now()
while True:
    verticalLine()
    puts(colored.cyan("Checking all printers"))
    espData = json.load(open("esp8266_data.json", "rt"))

    if len(espData) != len(printerList.getPrinters()):
        new_esp_list = list()
        for i, printer in enumerate(printerList.getPrinters()):
            esp_device = {
                "MODULE_ID": i,
                "R_Value": 0,
                "G_Value": 0,
                "B_Value": 0,
                "FAN_ON": False
            }
            new_esp_list.append(esp_device)
        espData = new_esp_list

    for i, printer in enumerate(printerList.getPrinters()):

        r = printer.get("api/v1/printer/status")