[docs]defdelete_recursively(path_folder,period=1,excluded_files=[]):""" Delete all the files and directory inside a directory which have been create before a certain period Paramters: path_folder(string): path to the fomlder to delete period(integer): in days: delete the file older than this period exluded_files(list<string>): list of files to not delete """forthe_fileinos.listdir(path_folder):file_path=os.path.join(path_folder,the_file)now=datetime.datetime.now()creation_date=datetime.datetime.utcfromtimestamp(os.path.getctime(file_path))is_older_than_period=(now-creation_date).days>=periodifis_older_than_period:ifos.path.isfile(file_path)andnotthe_fileinexcluded_files:os.unlink(file_path)elifos.path.isdir(file_path):shutil.rmtree(file_path)
[docs]defgenerate_pdf(template,data):# flask render a template by name with the given contexttemplate_rendered=render_template(template,data=data)# weasyprint HTML document parsedhtml_file=HTML(string=template_rendered,base_url=current_app.config["API_ENDPOINT"],encoding="utf-8")# weasyprint render the document to a PDF filereturnhtml_file.write_pdf()