Uposatha reminder emails using Google Sheets and Google App Scripts

I started playing around with Google App Scripts (GAS) for some projects and figured out how to send emails to remind me of the uposatha days. Anyone with a Gmail account can do it, so I thought I would post the basics here.

Google Apps Scripts is a way to automate things in the various Google products like Gmail and Google Sheets.

Create spreadsheet with dates

This bit is fairly straightforward. Just make sure that the dates are formatted as dates in the sheet.

Create the App Script

Under Extensions select Apps Script.
image

This will then open up the script editor.

Here is my code. GAS uses javascript with its own methods. It’s just a rough script. Lots of room for improvement I’m sure:

const ss = SpreadsheetApp.getActiveSheet()
const lastRow = ss.getLastRow()

function uposataEmails() {
  // get array of uposatha days
  const uposathaArray = ss.getRange(2, 1, lastRow - 1, 2).getValues()

  // see if today is an uposatha day
  uposathaArray.forEach(row => {
    const today = new Date();
    const uposathaDate = row[0]
    const uposathaType = row[1]

    if (today.toDateString() == uposathaDate.toDateString()) {
      MailApp.sendEmail("PUTYOUREMAILADDRESSHERE", "**Uposatha today** " + uposathaType, "Today is a " + uposathaType + " uposatha.")
    }
  })

}

Trigger

What makes the sending possible is creating a trigger to run the script daily.

First you will want to go into the spreadsheet’s settings and make sure the you have your correct time zone set.

Then in the script editor, you will want to open the Triggers interface:
image

You will then need to add a new trigger with the following settings:

Run the script

You will then need to run the script:

Running will initiate the authorization process. You will need to give google permission to access both your spreadsheet as well as your email account. It will give all kinds of ominous warnings, but since this is your script accessing your stuff, it’s not really an issue.

My suggestion is that you add the current date to the spreadsheet to test whether it fires correctly or not.

Enjoy!

5 Likes

Oh gosh, here I was just using the inbuilt uposatha bell reminder from the Thailand Buddhist calendar app for Android. I admire the dedication to do this with sheets!

Some terms to help with the app.
Phak khad: the “deficient” 14 day uposatha
Phak thuan: the 15th day uposatha

3 Likes

There is also Splendid Moons which makes .ics and related code here calculating-the-uposatha-moondays/README.md at master · profound-labs/calculating-the-uposatha-moondays · GitHub

2 Likes