Пример #1
0
 def __build_path_value(self, key, val=PathValue()):
     name = val.name if val.name is not None and val.name != "" else key
     if name in self.request.path_values:
         return PathValue(name=name, _value=self.request.path_values[name])
     else:
         raise HttpError(500,
                         "path name[%s] not in your url mapping!" % name)
Пример #2
0
 def return_picture(picture=PathValue(), function=PathValue()):
     logging.debug(function)
     my_pictures_path = "%s" %(Webserver.picture_dir)
     my_picture = "%s/%s" % (my_pictures_path, picture)
     logging.debug("Download picture from: %s" %my_picture)
     if function == 'download':
         return StaticFile(my_picture, "application/octet-stream")
     if function == 'show':
         return StaticFile(my_picture, "image/jpg")
     if function == 'delete':
         os.remove(my_picture)
         return Redirect("/")
     if function == '':
         return Redirect("/")
Пример #3
0
def image(path_val=PathValue()):
    ext = path_val[(path_val.rfind(".") + 1):]
    if ext == "png":
        mime = "image/png"
    elif ext == "jpg":
        mime = "image/jpeg"
    else:
        mime = "application/octet-stream"
    return StaticFile("./html/img/" + path_val, mime)
Пример #4
0
    def return_new_pictures(last_picture_timestamp=PathValue()):
        logging.debug("URL Timeparam: %s" %last_picture_timestamp)
        image_list = []
        new_pictures = []
        all_pictures = []

        my_last_picture_datetime= None

        if last_picture_timestamp.lower() == "undefined":
            return {}
        if last_picture_timestamp.upper() != "ALL":
            try:
                my_last_picture_datetime = datetime.datetime.fromtimestamp(float(last_picture_timestamp))
            except:
                my_last_picture_datetime = datetime.datetime.now()
                logging.warn("No valid timestamp")


        image_list=fnmatch.filter(os.listdir(Webserver.picture_dir), '*.jpg')
        current_picture_timestamp = None
        current_picture_information = {}
        for i in image_list:
            current_picture_information = Webserver.get_picture_meta_information(i)
            current_picture_timestamp = float(current_picture_information['picture_timestamp'])
            if my_last_picture_datetime is not None:
                print("current picture timestamp %s vs last picture timestamp %s" %(current_picture_timestamp, last_picture_timestamp))
                logging.debug("last picture timestamp: %s" %last_picture_timestamp)
                if current_picture_timestamp > float(last_picture_timestamp) and last_picture_timestamp.upper() != "ALL":
                    logging.debug("Send picture")
                    new_pictures.append(current_picture_information)
            all_pictures.append(current_picture_information)

        last_picture_information = max(all_pictures, key=lambda x:x['picture_timestamp'])

        return_pictures = []
        if last_picture_timestamp.upper() == "ALL":
            return_pictures = all_pictures
        else:
            return_pictures = new_pictures

        return_pictures = sorted(return_pictures, key=lambda k: k['picture_timestamp'])

        thisdict =	{
                "time_param": str(last_picture_timestamp),
                "last_picture": last_picture_information,
                "new_pictures": return_pictures,
                "now_datetime": str(datetime.datetime.now()),
                "now_timestamp": str(time()),
                "number_of_pictures": len(return_pictures),
                "photobooth_status": "free"
                }
        return thisdict
Пример #5
0
def html(path_val=PathValue()):
    with open(dt.path + "html/" + path_val, "r", encoding="utf-8") as f:
        read = f.read()
        f.close()
    ext = path_val[(path_val.rfind(".") + 1):]
    if ext == "html" or ext == "css":
        mime = "text/" + ext
    elif ext == "js":
        mime = "text/javascript"
    elif ext == "json":
        mime = "application/json"
    else:
        mime = "application/octet-stream"
    return 200, Headers({"Content-Type": mime}), read
Пример #6
0
 def return_picture(picture=PathValue(), function=PathValue()):
     logging.debug(function)
     my_pictures_path = "%s" %(Webserver.picture_dir)
     my_picture = "%s/%s" % (my_pictures_path, picture)
     if function == 'download':
         logging.debug("Download picture from: %s" %my_picture)
         return StaticFile(my_picture, "application/octet-stream")
     if function == 'show':
         logging.debug("Show picture from: %s" %my_picture)
         return StaticFile(my_picture, "image/jpg")
     if function == 'delete':
         logging.debug("Delete picture from: %s" %my_picture)
         os.remove(my_picture)
         return Redirect("/")
     if function == 'single':
         Webserver.html_header = Webserver.get_html_stream("header")
         return Webserver.get_full_html_stream("single_picture")
     if function == 'show_qr':
         qr_code_img_path = Webserver.generate_qr('show', picture)
         return StaticFile(qr_code_img_path, "image/jpg")
     if function == 'download_qr':
         qr_code_img_path = Webserver.generate_qr('download', picture)
         return StaticFile(qr_code_img_path, "image/jpg")
     if function == 'mail_qr':
         qr_code_img_path = Webserver.generate_qr('mail', picture)
         return StaticFile(qr_code_img_path, "image/jpg")
     if function == 'mail':
         logging.debug("Mail picture from: %s" %my_picture)
         my_return_stream =  Webserver.get_full_html_stream("frm_send_mail")
         my_return_stream = my_return_stream.replace("[picture_id]", picture)
         return my_return_stream
     if function == 'print':
         logging.debug("Print file %s ON: %s" %(my_picture, Webserver.printer))
         os.system("lpr -P %s %s" %(Webserver.printer, my_picture))
     else:
         return Redirect("/")
Пример #7
0
    def return_new_pictures(last_picture_timestamp=PathValue()):
        logging.debug("URL Timeparam: %s" %last_picture_timestamp)
        my_last_picture_timestamp = datetime.datetime.now()
        try:
            if last_picture_timestamp == 'undefined':
                my_last_picture_timestamp = datetime.datetime.now()
            else:
                my_last_picture_timestamp = datetime.datetime.fromtimestamp(int(last_picture_timestamp))
        except:
            my_last_picture_timestamp = datetime.datetime.now()
            logging.warn("No valid timestamp")

        image_list = []
        new_pictures = []
        image_list=fnmatch.filter(os.listdir(Webserver.picture_dir), '*.jpg')
        image_list.sort()
        for i in image_list:
            current_file = "%s/%s" %(Webserver.picture_dir,i)
            stat = os.stat(current_file)
            current_picture_timestamp = None
            try:
                current_picture_timestamp = stat.st_birthtime
            except AttributeError:
                # We're probably on Linux. No easy way to get creation dates here,
                # so we'll settle for when its content was last modified.
                current_picture_timestamp = stat.st_mtime
            logging.debug(current_picture_timestamp)
            current_picture_timestamp = datetime.datetime.fromtimestamp(current_picture_timestamp)
            print("current picture timestamp %s vs last picture timestamp %s" %(current_picture_timestamp, my_last_picture_timestamp))
            if current_picture_timestamp > my_last_picture_timestamp:
                logging.debug("Send picture")
                new_pictures.append(i)

        thisdict =	{
                "last_picture_timestamp": str(my_last_picture_timestamp),
                "new_pictures": new_pictures
                }
        return thisdict
Пример #8
0
def font(path_val=PathValue()):
    return StaticFile("./html/font/" + path_val, "application/x-font-ttf")
Пример #9
0
def my_path_val_ctr(pval: PathValue, path_val=PathValue()):
    return f"<html><body>{pval}, {path_val}</body></html>"
Пример #10
0
 def return_picture(picture=PathValue()):
     logging.debug("requesting information for picture %s" %picture)
     picture = "%s/%s" %(Webserver.picture_dir, picture)
     logging.debug(picture)
     picture_info = Webserver.get_picture_meta_information(picture)
     return picture_info
Пример #11
0
 def mail_picture(txt_email, txt_name, txt_message, picture=PathValue()):
     logging.debug("Post method mail picture to %s" %txt_name)
     my_pictures_path = "%s" %(Webserver.picture_dir)
     attachment = "%s/%s" % (my_pictures_path, picture)
     Webserver.send_simple_message(txt_name, txt_email, txt_message, picture, attachment)
     return Redirect("/")
Пример #12
0
 def get_js_file(js_file=PathValue()):
     my_js_file = "%s/js/%s" %(Webserver.root, js_file)
     return StaticFile(my_js_file, "text/javascript")
Пример #13
0
 def get_css_file(css_file=PathValue()):
     my_css_file = "%s/css/%s" %(Webserver.root, css_file)
     #my_css_stream = open(my_css_file, 'r').read()
     return StaticFile(my_css_file,  "text/css")
Пример #14
0
 def return_single_picture(picture=PathValue()):
     Webserver.html_header = Webserver.get_html_stream("header")
     return Webserver.get_full_html_stream("single_picture")