def generateSettings(path): profile = configparser.ConfigParser() profile.read_string(loadFromFile(path)) settings = [] if 'values' in profile.sections(): for option in profile.options('values'): settings.append('-s {0}="{1}"'.format(option, profile['values'][option])) return ' '.join(settings)
def slice(stlFileName, profilePath=None): stlPath = os.path.join(PATH, CONFIG['stl-upload-directory'], stlFileName) resultGcodePath = os.path.join(PATH, CONFIG['gcode-directory'], stlFileName) # settings = generateSettings(CONFIG['slicer']['profiles']['draft']) settings = loadFromFile( os.path.join(CONFIG['settings-directory'], CONFIG['slicer']['settings']['low'])) if not os.path.isfile(stlPath): return None, 'STL at {} does not exist'.format(stlPath) result, err = runSlicerCommand(stlPath, resultGcodePath, settings) return { 'printTime': int(re.findall(printTimeRegex, result)[0]), 'filament': int(re.findall(filamentRegex, result)[0]), }, err
def shutdown(target): printers = [] if(target == 'farm'): printers = loadConfig(PRINTERS_CONFIG_PATH)['printers'].keys() elif(target == 'printers'): printers = getSelectedPrinters() response = makeRequest(actions.COMMAND_SHUTDOWN, translatePrinterNamesToPrinterObjects(printers, loadConfig(PRINTERS_CONFIG_PATH))) if(target == 'farm'): shutdownCommand = loadFromFile(SHUTDOWN_SCRIPT_PATH) shutdownCommand = shutdownCommand.splitlines() for command in shutdownCommand: os.system(command) return json.dumps(response)
def order(): data = loads(request.form['data']) files = data['files'] filesDb = [] orderDb = Order(data['email'], data['phone'], delivery=data['delivery'], details=data['details']) orderPrice = 0 for file in files: fileDb = File.query.filter_by(id=file['id']).first() orderDb.files.append(fileDb) fileDb.filament = file['filament'] fileDb.amount = file['amount'] filesDb.append(fileDb) filament = FILAMENTS[file['filament']] individualItemPrice = price(fileDb.printTime, fileDb.filamentUsed, filament) individualPrice = individualItemPrice * file['amount'] orderPrice += individualPrice file['color'] = filament['color-name'] file['material'] = filament['material'] file['price'] = individualPrice file['priceItem'] = individualItemPrice file['name'] = fileDb.name file['content'] = loadFromFile(os.path.join( CONFIG['stl-upload-directory'], fileDb.fileName), bytes=True) deliveryPrice = 0 if data['delivery'] == 'express': deliveryPrice = round(orderPrice * CONFIG['express-delivery']) orderPrice = orderPrice + deliveryPrice orderPriceWithTax = round(orderPrice * CONFIG['tax']) orderDb.price = orderPrice dbSession.add(orderDb) dbSession.commit() orderId = orderDb.id @execute def sendMail(): filesDb = [] for file in files: fileDb = File.query.filter_by(id=file['id']).first() filesDb.append(fileDb) orderDb = Order.query.filter_by(id=orderId).first() email = Email(EMAIL_CONFIG['server'], EMAIL_CONFIG['port'], EMAIL_CONFIG['email'], EMAIL_CONFIG['password']) details = data['details'].replace('\n', '<br>') try: template = env.get_template('client.jinja2') content = template.render( files=files, price=orderPrice, priceWithTax=orderPriceWithTax, orderId=orderId, email=data['email'], delivery=additionalDeliveryInfo(data['delivery']), details=details, phone=data['phone'], deliveryPrice=deliveryPrice, ) messageForClient = email.createMessage( EMAIL_CONFIG['email'], data['email'], '3D továrna - objednávka č. S{orderId}'.format( orderId=orderId), content) email.send(messageForClient) orderDb.emailSentToClient = True dbSession.commit() except Exception as e: pass try: template = env.get_template('company.jinja2') content = template.render( files=files, price=orderPrice, priceWithTax=orderPriceWithTax, orderId=orderId, email=data['email'], delivery=additionalDeliveryInfo(data['delivery']), details=details, phone=data['phone'], deliveryPrice=deliveryPrice, ) messageForCompany = email.createMessage( EMAIL_CONFIG['email'], EMAIL_CONFIG['order-to'], '3D továrna - objednávka č. S{orderId}'.format( orderId=orderId), content, files, ) email.send(messageForCompany) orderDb.emailSentToCompany = True dbSession.commit() except Exception as e: pass return dumps({ 'message': 'new order was created', 'order': { 'orderId': orderId }, 'successful': True })