Fixed issue with variables not being updated in Excel file
This commit is contained in:
41
server.js
41
server.js
@@ -35,22 +35,33 @@ app.post('/calculate', async (req, res) => {
|
||||
await updateConfig(formData);
|
||||
console.log('Config file updated successfully');
|
||||
|
||||
// Run Python script to create Excel file
|
||||
exec('python3 create_excel.py', (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`Error executing Python script: ${error}`);
|
||||
console.error(`stderr: ${stderr}`);
|
||||
} else {
|
||||
console.log(`Python script output: ${stdout}`);
|
||||
// Run Python script to create Excel file synchronously
|
||||
const { execSync } = require('child_process');
|
||||
try {
|
||||
console.log('Executing Python script...');
|
||||
const stdout = execSync('python3 create_excel.py', { encoding: 'utf8' });
|
||||
console.log(`Python script output: ${stdout}`);
|
||||
|
||||
// Send success response after Python script completes
|
||||
res.json({
|
||||
success: true,
|
||||
message: 'Form data saved and Excel file created successfully'
|
||||
});
|
||||
console.log('Success response sent');
|
||||
} catch (execError) {
|
||||
console.error(`Error executing Python script: ${execError.message}`);
|
||||
if (execError.stderr) {
|
||||
console.error(`stderr: ${execError.stderr}`);
|
||||
}
|
||||
});
|
||||
|
||||
// Send success response
|
||||
res.json({
|
||||
success: true,
|
||||
message: 'Form data saved successfully'
|
||||
});
|
||||
console.log('Success response sent');
|
||||
|
||||
// Send error response for Python script failure
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: 'Error creating Excel file',
|
||||
error: execError.message
|
||||
});
|
||||
console.error('Error response sent for Python script failure');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error processing form data:', error);
|
||||
console.error('Error stack:', error.stack);
|
||||
|
||||
Reference in New Issue
Block a user