0

Running on Mac OS 10.12.6

I have a simple bot that logs me into a website daily. It's been functioning well with the following code for months until suddenly cron.schedule has stopped working. I can't seem to figure out what has changed or how to fix it.

Any help greatly appreciated.

const puppeteer = require("puppeteer-extra");
const cron = require("node-cron");
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
puppeteer.use(StealthPlugin());
const phoneApi = require('./config')
const client = require("twilio")(phoneApi.TWILIO_ACCOUNT_SID, phoneApi.TWILIO_AUTH_TOKEN);

const launchPup = async () => {
  const browser = await puppeteer.launch({
    headless: true,
  });

  const page = await browser.newPage();
  await page.setViewport({ width: 800, height: 600 });
  await page.goto(
    "https://prod.caseworthy.com/CaseWorthy/PortalDefault.aspx?DatabaseID=890&#/PortalLogin");

    await page.waitForSelector("#UserNameField");

  await page.type("#UserNameField", "USERNAME");
  await page.type("#PasswordField", "PASSWORD");
  await page.waitForTimeout(2000);
  await page.click("#btnLogin");
  await page.waitForTimeout(5000);
  try {
    await page.$("#popup_container");
    await page.click("#popup_ok");
    await page.waitForTimeout(5000);
    await page.waitForSelector("#content-inner");
    await page.click("#content-inner .section-inner button");
    await page.waitForTimeout(5000);
    await page.waitForSelector(".jconfirm .jconfirm-box");
    const element = await page.$(".jconfirm .jconfirm-box .content");
    const value = await page.evaluate((el) => el.textContent, element);
    console.log(value);
    await browser.close();
    sendMessage(value);
  } catch (err) {
    await page.waitForTimeout(5000);
    await page.waitForSelector("#content-inner");
    await page.click("#content-inner .section-inner button");
    await page.waitForTimeout(5000);
    await page.waitForSelector(".jconfirm .jconfirm-box");
    const element = await page.$(".jconfirm .jconfirm-box .content");
    const value = await page.evaluate((el) => el.textContent, element);
    console.log(value);
    await browser.close();
    sendMessage(value);
  }
};

const sendMessage = async (msg) => {
  client.messages
    .create({
      body: msg,
      from: "+18596483280",
      to: "+15038718395",
    })
    .then((message) =>
      console.log(
        "Message sent to +18596483280 here is the message id:" + message.sid
      )
    )
    .catch((err) => console.log(err));
  client.messages
    .create({
      body: msg,
      from: "+18596483280",
      to: "+16197199289",
    })
    .then((message) =>
      console.log(
        "Message sent to +18596483280 here is the message id:" + message.sid
      )
    );
};
console.log("Scheduling Messages To be Sent At 6 am");
cron.schedule(
  "* 0 6 * * *",
  () => {
    launchPup();
    console.log("Scheduling Messages To be Sent Tomorrow At 6 am");
  },
  {
    scheduled: true,
    timezone: "America/Los_Angeles",
  }
);

I've found this previous post, but not sure how to update the node-cron file path as I don't seem to have one on my system. Node.js script not executing from crontab

Also, not sure this is even the problem

0 Answers0