Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function init() {
prompt.start();
const { num } = await prompt.getAsync(schema);
const { data } = await axios(`${base}/api/problems/all/`);
const item = _.find(data.stat_status_pairs, item => item.stat.frontend_question_id === num);
if (!item) {
throw new Error(`${num} is not found`);
}
const browser = await puppeteer.launch();
const page = await browser.newPage();
await setLanguage(page);
// load the problem page, it may need to adjust the timeout
await createProblem(page, item.stat);
await browser.close();
}
},
];
for (let i = 0; i < items.length; i++) {
console.log(`${i + 1}. ${items[i]}${(' '.repeat(width - items[i].length))}${prices[items[i]]}`);
}
const onError = function onError(err) {
console.log(err.message);
process.exit();
};
let price = -1;
Promise.promisifyAll(prompt);
prompt.start();
prompt.getAsync(itemProps).then((response) => {
if (response.item > items.length || response.item < 1) {
onError(new Error('Chosen item does not exist.'));
}
price = prices[items[response.item - 1]];
return prompt.getAsync(amountProps);
}).then((response) => {
const change = calculateChange(price, parseFloat(response.amount));
console.log(`Your change: ${JSON.stringify(change)}`);
});
current = current.then(function() {
console.log('Title: "' + screencast.title + '".');
return prompt.getAsync(property);
}).then(function(result) {
if (result.approve === 'yes') {
prompt.getAsync(itemProps).then((response) => {
if (response.item > items.length || response.item < 1) {
onError(new Error('Chosen item does not exist.'));
}
price = prices[items[response.item - 1]];
return prompt.getAsync(amountProps);
}).then((response) => {
const change = calculateChange(price, parseFloat(response.amount));