Skip to content
Snippets Groups Projects
Commit 2172680d authored by John Titus's avatar John Titus
Browse files

init

parents
Branches
No related tags found
No related merge requests found
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.pnp.*
# Bungholio
Monitors Amazon and sends a text when watched products become available. It will send a text at most once per day per product.
## Installation
1. Clone this repo.
2. Modify items.json with the name and url of products you want to watch.
3. Create a .env file with the following Twilio attributes
```
accountSid=twilioSid
authToken=TwilioAuthToken
twilioFrom='+yourTwilioPhoneNumber'
twilioTo='+phoneNumberToText'
```
4. Run it
```
node index.js
```
index.js 0 → 100644
const puppeteer = require('puppeteer');
const Promise = require('bluebird');
const fs = require('fs');
const moment = require('moment');
require('dotenv').config();
const client = require('twilio')(process.env.accountSid, process.env.authToken);
const file = require('./items');
const items = file.items;
async function checkItem(page, item) {
console.log(`Checking ${item.name}`);
await page.goto(item.url);
const canAdd = await page.$('#add-to-cart-button');
const notInStock = (await page.content()).match(/in stock on/gi);
return canAdd && !notInStock;
}
async function sendSMS(item) {
return client.messages.create({
body: `${item.name} available! ${item.url}`,
from: process.env.twilioFrom,
to: process.env.twilioTo
});
}
async function run() {
console.log('');
console.log(`Starting at ${moment().toISOString()}`);
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({
width: 1680,
height: 1050
});
await Promise.map(
items,
async item => {
const oneDayAgo = moment().subtract(1, 'days');
if (!item.found || moment(item.found).isBefore(oneDayAgo)) {
const available = await checkItem(page, item);
if (available) {
item.found = moment().toISOString();
console.log(`${item.name} is available.`);
await sendSMS(item);
} else {
console.log(`${item.name} is not available.`);
}
console.log('Waiting...');
return Promise.delay(4000);
}
},
{ concurrency: 1 }
);
const update = { items: items };
console.log('finishing...');
fs.writeFileSync('items.json', JSON.stringify(update, null, 4));
await browser.close();
console.log('browser closed');
return;
}
run();
setInterval(async function() {
await run();
console.log('back');
console.log('waiting 15 minutes');
}, 15 * 60 * 1000);
{
"items": [
{
"name": "Charmin TP",
"url": "https://www.amazon.com/gp/product/B0798C1NYR/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1"
},
{
"name": "Presto Paper Towels",
"url": "https://www.amazon.com/gp/product/B07QY8P3B1/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1"
},
{
"name": "Angel Soft TP",
"url": "https://www.amazon.com/Angel-Soft-Toilet-Double-Regular/dp/B07SPY4HM8/ref=sr_1_1?crid=9RJ5GS2DWFKQ&keywords=toilet+paper&qid=1585684440&sprefix=toil%2Chpc%2C143&sr=8-1"
},
{
"name": "test tshirt",
"url": "https://www.amazon.com/Jerzees-Heavyweight-Sleeve-T-Shirt-Heather/dp/B00BBW7REI/ref=sr_1_1?dchild=1&keywords=tsjort&qid=1585676131&sr=8-1",
"found": "2020-03-31T21:44:33.609Z"
}
]
}
\ No newline at end of file
This diff is collapsed.
{
"name": "bungholio",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"bluebird": "^3.7.2",
"dotenv": "^8.2.0",
"moment": "^2.24.0",
"puppeteer": "^2.1.1",
"twilio": "^3.41.1"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment