Puppeteer. Automate sending report summary to CEO

Narongsak Keawmanee
Medvine Tech
Published in
2 min readNov 4, 2018
Example data — Geckoboard

At Medvine. We use Geckoboard for visualize business data such as gross merchandise volume, average order value, new customer per month, order total per month. these data help for analysis business and planing marketing strategies. so it very important to send summary every 11.59 PM(the end of the day) to CEO every day.

From previous article Puppeteer. Make yourself at chrome. I already present how to use Puppeteer to do automate things with web browser. In this article I will present how to use them in real world project which is auto send email of Geckoboard data to CEO every 11.59 PM.

Let Code!

In NodeJs. have package to help us to catch the time we want then trigger the function to execute. that package is node-cron.

// install
yarn add node-cron

then at server.js file. we need to set time for execute

const cron = require('node-cron');cron.schedule('0 59 23 * * *', function (){
// function will execute every 11.59 pm
}

Then in function. I use Puppeteer to open website. then take screenshot and save in local directory.

line 10–13: in linux we need to tell chromium do not running with GPU otherwise chromium will stop working.

line 15: I set viewport for get height resolution otherwise image will not clear.

And next we need to install package call nodemailer for help us to sending email easier.

// install
yarn add nodemailer

Then make function call sendmail

This function will sendmail to people we add in mailOpstions. when email send successfully. we will delete screenshot file in our server.

And don’t forget to call this function. just add this after await browser.close();

await browser.close();
sendmail(todaydate)

And we got email from Bot like this

email from Medvine bot

Puppeteer can make everything that you can imagine. now imagine and start write code!

I appreciated all cup of coffee. you can donate coffee at button below.

https://www.buymeacoffee.com/klogic

--

--

Narongsak Keawmanee
Medvine Tech

Software Engineer at Refinitiv • Highly ambitious • Love working with great people • Never Stop Learning