Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: webpage toggle, sound notification, fix evga links #52

Merged
merged 8 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ SLACK_TOKEN="slack-token"
STORES="bestbuy,bandh,nvidia"
PHONE_NUMBER="1234567890"
PHONE_CARRIER="tmobile"
OPEN_BROWSER="true"
PLAY_SOUND="false"
SCREENSHOT="true"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ First, you're going to need to copy the `.env.example` to `.env`. The current op
| `SLACK_CHANNEL` | Slack channel for posting (e.g., `update`); optional |
| `SLACK_TOKEN` | Slack API token; optional
| `STORES` | List of [stores](#Supported-stores) you want to be scraped; optional, default: `nvidia` |
| `OPEN_BROWSER` | Toggle for whether or not the browser should open when item is found, default: `true` |
| `PLAY_SOUND` | Play sound notification if a card is found, default: `false` |
| `SCREENSHOT` | Capture screenshot of page on successful hit; optional, default `true` |

> :point_right: If you have multi-factor authentication (MFA), you will need to create an [app password](https://myaccount.google.com/apppasswords) and use this instead of your Gmail password.
Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@types/node": "^14.11.1",
"@types/nodemailer": "^6.4.0",
"@types/puppeteer": "^3.0.2",
"play-sound": "^1.1.3",
"rimraf": "^3.0.2",
"typescript": "^4.0.2",
"xo": "^0.33.1"
Expand Down
Binary file added resources/notification-sound.wav
Binary file not shown.
8 changes: 6 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const notifications = {
channel: process.env.SLACK_CHANNEL ?? '',
token: process.env.SLACK_TOKEN ?? ''
},
test: process.env.NOTIFICATION_TEST ?? 'false'
test: process.env.NOTIFICATION_TEST ?? 'false',
playSound: process.env.PLAY_SOUND ?? 'false'
};

const page = {
Expand All @@ -32,9 +33,12 @@ const rateLimitTimeout = Number(process.env.RATE_LIMIT_TIMEOUT) ?? 5000;

const stores = process.env.STORES ?? 'nvidia';

const openBrowser = process.env.OPEN_BROWSER ?? 'true';

export const Config = {
notifications,
rateLimitTimeout,
page,
stores
stores,
openBrowser
};
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ async function lookup(store: Store) {
}

const givenUrl = store.cartUrl ? store.cartUrl : link.url;
await open(givenUrl);

if (Config.openBrowser === 'true') {
await open(givenUrl);
}

sendNotification(givenUrl);
}

Expand Down
5 changes: 5 additions & 0 deletions src/notification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Config} from '../config';
import sendEmail from './email';
import sendSlaskMessage from './slack';
import sendSMS from './sms';
import playSound from './sound';

export default function sendNotification(cartUrl: string) {
if (Config.notifications.email.username && Config.notifications.email.password) {
Expand All @@ -18,4 +19,8 @@ export default function sendNotification(cartUrl: string) {
sendSMS(cartUrl);
}
}

if (Config.notifications.playSound === 'true') {
playSound();
}
}
15 changes: 15 additions & 0 deletions src/notification/sound.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import playerLib = require('play-sound');
import {Logger} from '../logger';

const notificationSound = './resources/notification-sound.wav';
const player = playerLib();

export default function playSound() {
player.play(notificationSound, (err: string) => {
Logger.info('✔ playing sound');

if (err) {
Logger.error(`error playing sound: ${err}`);
}
});
}
1 change: 1 addition & 0 deletions src/play-sound.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'play-sound';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets put this into src/types

23 changes: 21 additions & 2 deletions src/store/evga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,29 @@ export const Evga: Store = {
links: [
{
brand: 'evga',
model: 'ftw3, xc3 black, xc3 gaming, xc3 ultra gaming',
url: 'https://www.evga.com/products/productlist.aspx?type=0&family=GeForce+30+Series+Family&chipset=RTX+3080',
model: 'xc3 black',
url: 'https://www.evga.com/products/product.aspx?pn=10G-P5-3881-KR',
oosLabels: ['out of stock']
},
{
brand: 'evga',
model: 'ftw3',
url: 'https://www.evga.com/products/product.aspx?pn=10G-P5-3897-KR',
oosLabels: ['out of stock']
},
{
brand: 'evga',
model: 'xc3 gaming',
url: 'https://www.evga.com/products/product.aspx?pn=10G-P5-3883-KR',
oosLabels: ['out of stock']
},
{
brand: 'evga',
model: 'xc3 ultra gaming',
url: 'https://www.evga.com/products/product.aspx?pn=10G-P5-3885-KR',
oosLabels: ['out of stock']
}
],
name: 'evga'
};