def do_conversion(file): filename = secure_filename(file.filename) timestamp = int(time.time()) filename_ts = '%s.vue' % timestamp file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename_ts)) conv = Converter(filename_ts, session['title'], { 'uploads': app.config['UPLOAD_FOLDER'], 'downloads': app.config['DOWNLOAD_FOLDER']}) conv.convert2markdown() return timestamp
def do_conversion(file): filename = secure_filename(file.filename) timestamp = int(time.time()) filename_ts = '%s.vue' % timestamp file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename_ts)) conv = Converter( filename_ts, session['title'], { 'uploads': app.config['UPLOAD_FOLDER'], 'downloads': app.config['DOWNLOAD_FOLDER'] }) conv.convert2markdown() return timestamp
def upload_file(): if request.method == 'POST': title = request.form['title'] session['title'] = title file = request.files['file'] timestamp = create_timestamp() conv = Converter(title, FOLDERS, timestamp) app.logger.info(timestamp) session['timestamp'] = timestamp app.logger.info(file) try: extension = conv.extract_filetype(file.filename) app.logger.info(extension) if not extension: raise try: # Construct the filename from the timestamp and the extension filename = '%s.%s' % (timestamp, extension) app.logger.debug(conv.make_timestamp_directories()) try: conv.save_upload(filename, file) if extension == 'vpk': conv.unpack() flash('That worked!', category='success') return render_template('done.html', timestamp=timestamp) except: flash('Oops, there was an error! Could not save the file!', category='danger') return redirect(url_for('index')) except: flash( 'Oops, there was an error! Could not create the upload directory!', category='danger') return redirect(url_for('index')) except: flash('Oops, there was an error! Perhaps not a VUE or VPK file?', category='danger') return redirect(url_for('index')) return render_template('about.html')
def download_files(type, timestamp): allowed_download_types = ['pdf', 'html', 'markdown', 'odt'] timestamp = '%s' % timestamp if type not in allowed_download_types: return "No valid download type!" else: conv = Converter(session['title'], FOLDERS, timestamp) download_folder = os.path.join(FOLDERS['downloads'], timestamp) conv.prepare_xml() if type == 'pdf': conv.convert2markdown() try: conv.convert2pdf() filename = '%s.pdf' % timestamp return send_from_directory(download_folder, filename, as_attachment=True) except: return redirect(url_for('error')) elif type == 'html': conv.convert2markdown() conv.convert2html() filename = '%s.html' % timestamp return send_from_directory(download_folder, filename, as_attachment=True) elif type == 'odt': conv.convert2markdown() conv.convert2odt() filename = '%s.odt' % timestamp return send_from_directory(download_folder, filename, as_attachment=True) elif type == "markdown": conv.convert2markdown() filename = '%s.md' % timestamp return send_from_directory(download_folder, filename, as_attachment=True)