Update index.js
This commit is contained in:
parent
93985a6837
commit
e5ea735a3d
18
index.js
18
index.js
|
|
@ -166,7 +166,7 @@ async function scrapeWithCheerio(url) {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendMail(subject, body, isError = false) {
|
async function sendMail(subject, body) {
|
||||||
try {
|
try {
|
||||||
await axios({
|
await axios({
|
||||||
url: process.env.API_DISTI_HOST + "/api/export/items-sold-out",
|
url: process.env.API_DISTI_HOST + "/api/export/items-sold-out",
|
||||||
|
|
@ -201,14 +201,12 @@ async function sendMail(subject, body, isError = false) {
|
||||||
to: EMAILS.join(","),
|
to: EMAILS.join(","),
|
||||||
subject,
|
subject,
|
||||||
text: body,
|
text: body,
|
||||||
attachments: isError
|
attachments: [
|
||||||
? []
|
{
|
||||||
: [
|
filename: fileName,
|
||||||
{
|
content: response.data, // attach from memory
|
||||||
filename: fileName,
|
},
|
||||||
content: response.data, // attach from memory
|
],
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
await transporter.sendMail(mailOptions);
|
await transporter.sendMail(mailOptions);
|
||||||
|
|
@ -270,7 +268,7 @@ async function main() {
|
||||||
|
|
||||||
if (errors.length > 3) {
|
if (errors.length > 3) {
|
||||||
const msg = errors.map((e) => `URL: ${e.url}\nMessage: ${e.message}`).join("\n\n");
|
const msg = errors.map((e) => `URL: ${e.url}\nMessage: ${e.message}`).join("\n\n");
|
||||||
await sendMail("[New Items] - Scraping Sold Out Error Report", msg, true);
|
await sendMail("[New Items] - Scraping Sold Out Error Report", msg);
|
||||||
} else {
|
} else {
|
||||||
const msg = inserted.map((i) => `Shop: ${i.name}\nSold: ${i.count} items`).join("\n\n");
|
const msg = inserted.map((i) => `Shop: ${i.name}\nSold: ${i.count} items`).join("\n\n");
|
||||||
await sendMail("[New Items] - Scraping Sold Out Success", msg);
|
await sendMail("[New Items] - Scraping Sold Out Success", msg);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue