Chwishlist
@jessekuntz
code:
data:privatelast updated:1 year ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 1,000,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
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) => {
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
const fetch = require('isomorphic-fetch')
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const tableify = require('tableify');
const juice = require('juice');

const animals = ['🦓', '🦒', '🦔', '🦕', '🦖', '🦝', '🦙', '🦛', '🦘', '🦡', '🦚', '🦢', '🦜', '🦞', '🕊', '🐀', '🐁', '🐂', '🐃', '🐄', '🐅', '🐆', '🐇', '🐈', '🐉', '🐊', '🐋', '🐌', '🐍', '🐎', '🐏', '🐐', '🐑', '🐒', '🐝', '🐠', '🐢', '🐥', '🐫', '🐩', '🐡', '🦈', '🦀', '🦎', '🦏', '🦑', '🦄'];

const prices = [];
const pricesToHighlight = [];

function createAnchor(url, text) {
  return `<a href="${url}">${text}</a>`
}

function emailTrimRemover() {
  const uniqueContent = `<span style="opacity: 0"> ${Date.now()} </span>`;

  return `<div> <p></p> ${uniqueContent} </div>`
}

async function setPrice(url, goalPrice) {
  const response = await fetch(url);
  const text = await response.text();

console.log(text)

  const dom = await new JSDOM(text);
  let title = dom.window.document.querySelector("h1").textContent.trim();
  const titleWords = title.split(' ');

  if (titleWords.length > 5) {
    title = titleWords.splice(0, 5).join(' ') + '...';
  }

  let price;

  try {
    price = dom.window.document.querySelector(".kib-product-price").textContent;
    price = parseFloat(price.trim().slice(1).substring(0, price.indexOf("Chewy")));
  } catch(e) {
    console.log(e);
    price = "?";
  }

  const row = {product: createAnchor(url, title), current: `$${price}`, goal: `$${goalPrice}`};

  prices.push(row);

  if (price < goalPrice) {
    pricesToHighlight.push(row)
  }
}

async function setPrices() {
  await setPrice('https://www.chewy.com/tiki-cat-aloha-friends-variety-pack/dp/130430', 10.00);
  await setPrice('https://www.chewy.com/tiki-cat-born-carnivore-herring/dp/266430', 15.00);
  await setPrice('https://www.chewy.com/tiki-cat-born-carnivore-chicken-egg/dp/266429', 40.00);
  await setPrice('https://www.chewy.com/tiki-cat-born-carnivore-chicken/dp/266435', 40.00);
  await setPrice('https://www.chewy.com/fresh-news-unscented-non-clumping/dp/46608', 15.00);
}

await setPrices();

const highlightedPricesTableHTML = pricesToHighlight.length ? tableify(pricesToHighlight) : `<p> No current 🌶 deals 😿 </p>`;
const pricesTableHTML = tableify(prices);

const css = '<style> body { font-family: "Roboto", helvetica, arial, sans-serif; font-size: 16px; font-weight: 400; text-rendering: optimizeLegibility; } h3 { color: #1b1e24; font-size: 30px; font-weight: 400; text-transform: uppercase; text-align: center; } p {color: #1b1e24; text-align: center; } table { border: 4px solid #1b1e24; border-spacing: 0px; border-radius: 4px; margin: auto; width: 100%; max-width: 800px; } th { color: white; background: #1b1e24; border-right: 1px solid #343a45; font-size: 18px; padding: 12px; } th:last-child { border-right: none; } tr:hover td { background: #4E5066; color: #FFFFFF; } tr:nth-child(odd) td { background: #EBEBEB; } tr:nth-child(odd):hover td { background: #4E5066; } td { background: #FFFFFF; padding: 12px; border-right: 1px solid #C1C3D1; } td:last-child { border-right: 0px; } a { color: #108CED; } </style>';
const html = juice(`<html lang="en"> <body> <h3>Hottest Deals 🔥</h3> ${highlightedPricesTableHTML} <h3>All Prices 💰</h3> ${pricesTableHTML} ${emailTrimRemover()} <p> Sent by your favorite Chwishlist cat 😸 </p> </body> ${css} </html>`);

const date = new Date();
const animal = animals[Math.floor(Math.random() * animals.length)];

this.subject = `Your Chewy Prices for ${date.getMonth() + 1}/${date.getDate()} ${animal}`;
this.html = html;
this.text = `Hottest Prices:\n${JSON.stringify(pricesToHighlight)}\nNormal Prices:\n${JSON.stringify(prices)}`;
steps.
email_me
Customize and send an email to the email address you registered with Pipedream. The email will be sent by notifications@pipedream.com.
params
Subject
 
string ·params.subject
Text
 
string ·params.text
Optional
code
async params => {
1
2
3
4
5
6
7
8
9
10
11
12
}
13
const options = {
  subject: params.subject,
  text: params.text,
}
if (params.html) {
  options.html = params.html
}
if (params.include_collaborators) {
  options.include_collaborators = params.include_collaborators
}
$send.email(options)