COVID Alerts
@dylan
code:
data:privatelast updated:3 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 800,000+ developers using the Pipedream platform
steps.
trigger
Cron Scheduler
Deploy to configure a custom schedule
This workflow runs on Pipedream's servers and is triggered on a custom schedule.
steps.
nodejs
auth
to use OAuth tokens and API keys in code via theauths object
(auths.browserless)
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
}
114
const axios = require("axios")
const cheerio = require("cheerio")
const puppeteer = require('puppeteer-core') 

// Use Browserless to hit sites that render content via JS
const browser = await puppeteer.connect({ 
  browserWSEndpoint: `wss://chrome.browserless.io?token=${auths.browserless.api_key}` 
})
const page = await browser.newPage()

async function fetchHTML(url) {
  const { data } = await axios.get(url)
  return cheerio.load(data)
}

// Retrieve last known text from each site
const checkpoint = $checkpoint || {}

try {
  // Hackensack
  /* const hackensackHealthURL = "https://www.hackensackmeridianhealth.org/covid19/"
  const hackensackHealth = await fetchHTML(hackensackHealthURL)
  this.hackensackHealthText = hackensackHealth('#pagealert2 > strong').text()

  if (checkpoint['hackensacker'] !== this.hackensackHealthText) {
    $send.email({
      subject: "COVID ALERT",
      text: `Hackensack Meridian: ${hackensackHealthURL}`,
    })

    checkpoint['hackensacker'] = this.hackensackHealthText
  } */

  // Princeton Health
  /* const princetonURL = "https://www.princetonhcs.org/"
  const princeton = await fetchHTML(princetonURL)
  this.princetonText = princeton('body > div > div.emergency-notice > div > div.emergency-notice__blurb > div > div > p').text()

  if (checkpoint['princeton'] !== this.princetonText) {
    $send.email({
      subject: "COVID ALERT",
      text: `Princeton Health: ${princetonURL}`,
    })

    checkpoint['princeton'] = this.princetonText
  } */

  // ShopRite
  const shopRiteURL = "https://vaccines.shoprite.com/"
  await page.goto(shopRiteURL)
  const sselector = '#main > div:nth-child(2) > div > div'
  await page.waitForSelector(sselector);

  const shopRiteDiv = await page.$(sselector)
  this.shopRiteText = await page.evaluate(shopRiteDiv => shopRiteDiv.textContent, shopRiteDiv);

  if (checkpoint['shopRite'] !== this.shopRiteText) {
    $send.email({
      subject: "COVID ALERT",
      text: `ShopRite: ${shopRiteURL}`,
    })

    checkpoint['shopRite'] = this.shopRiteText
  }

  // CVS
  const cvsURL = "https://www.cvs.com/immunizations/covid-19-vaccine#statetool"
  await page.goto(cvsURL)

  // First, select the New Jersey link to appear
  const stateSelector = 'a[data-analytics-name="New Jersey"]'
  await page.waitForSelector(stateSelector);
  await page.click(stateSelector)

  // Then get the vaccine status text that appears
  const cvsSelector = '#vaccineinfo-NJ > div > div > div > div.aem-Grid.aem-Grid--12.aem-Grid--default--12 > div.box.parbase.aem-GridColumn.aem-GridColumn--default--12 > div > div > div.content__wrapper.parsecondary > div > div.covid-updates.aem-GridColumn.aem-GridColumn--default--12 > div > div'
  await page.waitForSelector(cvsSelector);
  const cvsSpan = await page.$(cvsSelector)
  this.cvsText = await page.evaluate(cvsSpan => cvsSpan.textContent, cvsSpan);

  if (checkpoint['cvs'] !== this.cvsText) {
    $send.email({
      subject: "COVID ALERT",
      text: `CVS: ${cvsURL}`,
    })

    checkpoint['cvs'] = this.cvsText
  }

  // Riverside Medical Group
  /* const riversideURL = "https://form.jotform.com/210033944227044"
  const riverside = await fetchHTML(riversideURL)
  this.riversideText = riverside('#header_8').text()

  if (checkpoint['riverside'] !== this.riversideText) {
    $send.email({
      subject: "COVID ALERT",
      text: `Riverside Medical Group: ${riversideURL}`,
    })

    checkpoint['riverside'] = this.riversideText
  } */
} catch (err) {
  $send.email({
    subject: "Error in COVID script",
    text: err,
  })
} finally {
  // Persist new text to $checkpoint
  $checkpoint = checkpoint
  browser.close();
}