Skip to content

Commit 1642c87

Browse files
committed
Reorganize files
1 parent af4adc8 commit 1642c87

18 files changed

+180
-103
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Currently, the following stores are supported:
3838
`npm install`
3939

4040
### Usage
41-
1. Open and edit main.js
41+
1. Open and edit `config.js`
4242
* Add urls of products in the `URLS` array
4343
* Change the `INTERVAL` to suit your desires.\
4444
**WARNING:** Having the interval too low might have negative consquences such as this program being detected as a bot (Amazon), or blocking your IP from accessing the website.
@@ -55,7 +55,9 @@ Currently, the following stores are supported:
5555
4. Paste it to `TARGET_KEY`
5656
* **If** you want to send alerts to webhook URL(s) like [Discord](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) or [Slack](https://api.slack.com/messaging/webhooks), add them to `WEBHOOK_URLS` array
5757
2. Execute and continue about your day
58-
`node main.js`
58+
`node main.js`\
59+
OR\
60+
`npm start`
5961
3. Consider buying me a [Pizza](https://buymeacoff.ee/PrinceSingh) or [PayPal'ing](https://paypal.me/PrinceSingh25) me
6062

6163
### Things to work on

config.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"__URLS_comment": [
3+
"All the products to check",
4+
"Current domains supported: Amazon, AntOnline, Argos, Best Buy, Costco, Currys, Microcenter, Newegg, Target, Tesco",
5+
"Format: https://www.ABC123.com/..."
6+
],
7+
"URLS": [
8+
"https://www.antonline.com/Sony/Electronics/Gaming_Devices/Gaming_Consoles/1413553",
9+
"https://www.currys.co.uk/gbuk/gaming/console-gaming/consoles/microsoft-xbox-series-x-1-tb-10203371-pdt.html"
10+
],
11+
12+
13+
"__INTERVAL_comment": [
14+
"How often to check for products. Too often may be dangerous, especially for Amazon",
15+
"Units: seconds, m: minutes, h: hours"
16+
],
17+
"INTERVAL": {
18+
"unit": "seconds",
19+
"value": 10
20+
},
21+
22+
23+
"__OPEN_URL_comment": [
24+
"Opens the product url in your default browser if set to true"
25+
],
26+
"OPEN_URL": true,
27+
28+
29+
"__ALARM_comment": [
30+
"Makes a sound when a product is in stock"
31+
],
32+
"ALARM": true,
33+
34+
35+
"__AMAZON_DELAY_comment": [
36+
"IF YOU ENTERED A AMAZON PRODUCT",
37+
"Separates the check between Amazon items by this value"
38+
],
39+
"AMAZON_DELAY": 10,
40+
41+
42+
"__TARGET_ZIP_CODE_comment": [
43+
"IF YOU ENTERED A TARGET PRODUCT",
44+
"Enter your zip code to search for a Target closest to you"
45+
],
46+
"TARGET_ZIP_CODE": "90024",
47+
48+
49+
"__TARGET_KEY_comment": [
50+
"IF YOU ENTERED A TARGET PRODUCT AND YOU GET API KEY ERRORS",
51+
"Enter the key for your session as described in the README"
52+
],
53+
"TARGET_KEY": "ff457966e64d5e877fdbad070f276d18ecec4a01",
54+
55+
56+
"__WEBHOOK_URLS_comment": [
57+
"IF YOU WANT SLACK OR DISCORD WEBHOOKS"
58+
],
59+
"WEBHOOK_URLS": [
60+
""
61+
]
62+
}

main.js

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,7 @@
11

2-
/*
3-
**************************************** EDIT THESE ****************************************
4-
*************************************** AS NECESSARY ***************************************
5-
*/
6-
7-
// All the products to check
8-
// Current domains supported: Amazon, AntOnline, Argos, Best Buy, Costco, Currys, Microcenter, Newegg, Target, Tesco
9-
// Format: https://www.XXX.com/...
10-
const URLS = [
11-
// "https://www.amazon.com/gp/product/B08164VTWH/",
12-
"https://www.amazon.com/PlayStation-5-Console/dp/B08FC5L3RG",
13-
"https://www.antonline.com/Sony/Electronics/Gaming_Devices/Gaming_Consoles/1413553",
14-
"https://www.argos.co.uk/product/8349000",
15-
"https://www.bestbuy.com/site/amd-ryzen-9-5900x-4th-gen-12-core-24-threads-unlocked-desktop-processor-without-cooler/6438942.p?skuId=6438942",
16-
"https://www.costco.com/sony-playstation-5-gaming-console-bundle.product.100691489.html",
17-
"https://www.currys.co.uk/gbuk/gaming/console-gaming/consoles/microsoft-xbox-series-x-1-tb-10203371-pdt.html",
18-
"https://www.microcenter.com/product/630283/Ryzen_9_5900X_Vermeer_37GHz_12-Core_AM4_Boxed_Processor",
19-
"https://www.newegg.com/amd-ryzen-9-5900x/p/N82E16819113664?Item=N82E16819113664",
20-
"https://www.target.com/p/playstation-5-console/-/A-81114595",
21-
"https://www.tescopreorders.com/uk/ps5",
22-
// "https://www.tesco.com/groceries/en-GB/products/306276176",
23-
]
24-
25-
// How often to check for products. Too often may be dangerous, especially for Amazon.
26-
const INTERVAL = {
27-
unit: 'seconds', // seconds, m: minutes, h: hours
28-
value: 10
29-
}
30-
31-
// Opens the product url in your default browser if set to true
32-
export const OPEN_URL = true; // true, false
33-
34-
// Makes a sound when a product is in stock
35-
export const ALARM = true; // true, false
36-
37-
// IF YOU ENTERED A AMAZON PRODUCT
38-
// Separates the check between Amazon items by this value
39-
const AMAZON_DELAY = 10;
40-
41-
// IF YOU ENTERED A TARGET PRODUCT
42-
// Enter your zip code to search for a Target closest to you
43-
export const TARGET_ZIP_CODE = '90024'
44-
45-
// IF YOU ENTERED A TARGET PRODUCT AND YOU GET API KEY ERRORS
46-
// Enter the key for your session as described in the README
47-
export const TARGET_KEY = 'ff457966e64d5e877fdbad070f276d18ecec4a01'
48-
49-
// IF YOU WANT SLACK OR DISCORD WEBHOOKS
50-
export const WEBHOOK_URLS = [
51-
""
52-
]
53-
54-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ END ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55-
56-
2+
// Support require
3+
import { createRequire } from "module";
4+
const require = createRequire(import.meta.url);
575

586
import { fileURLToPath } from "url";
597
import antonline from './stores/antonline.js'
@@ -68,6 +16,33 @@ import target from './stores/target.js'
6816
import tesco from './stores/tesco.js'
6917

7018

19+
// Import configs
20+
export var {
21+
URLS,
22+
INTERVAL,
23+
OPEN_URL,
24+
ALARM,
25+
AMAZON_DELAY,
26+
TARGET_ZIP_CODE,
27+
TARGET_KEY,
28+
WEBHOOK_URLS
29+
} = require('./config.json')
30+
31+
const ADDITIONAL_URLS = [
32+
// "https://www.amazon.com/PlayStation-5-Console/dp/B08FC5L3RG",
33+
"https://www.amazon.com/gp/product/B08164VTWH/",
34+
"https://www.argos.co.uk/product/8349000",
35+
"https://www.bestbuy.com/site/amd-ryzen-9-5900x-4th-gen-12-core-24-threads-unlocked-desktop-processor-without-cooler/6438942.p?skuId=6438942",
36+
"https://www.costco.com/sony-playstation-5-gaming-console-bundle.product.100691489.html",
37+
"https://www.microcenter.com/product/630283/Ryzen_9_5900X_Vermeer_37GHz_12-Core_AM4_Boxed_Processor",
38+
"https://www.newegg.com/amd-ryzen-9-5900x/p/N82E16819113664?Item=N82E16819113664",
39+
"https://www.target.com/p/playstation-5-console/-/A-81114595",
40+
"https://www.tescopreorders.com/uk/ps5",
41+
// "https://www.tesco.com/groceries/en-GB/products/306276176",
42+
]
43+
if (ADDITIONAL_URLS.length > 0) URLS = URLS.concat(ADDITIONAL_URLS)
44+
45+
7146
// Runs main only if this file is executed
7247
if (process.argv[1] === fileURLToPath(import.meta.url))
7348
main();

package-lock.json

Lines changed: 34 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
{
2+
"name": "stock-alert-bot",
3+
"version": "1.0.0",
4+
"description": "Get alerts when items come in stock",
25
"type": "module",
6+
"main": "main.js",
7+
"scripts": {
8+
"start": "node main.js"
9+
},
310
"dependencies": {
411
"axios": "^0.21.1",
512
"beepbeep": "^1.3.0",
613
"dom-parser": "^0.1.6",
714
"moment": "^2.29.1",
815
"open": "^7.3.0"
9-
}
16+
},
17+
"repository": {
18+
"type": "git",
19+
"url": "git+https://github.com/PrinceS25/StockAlertBot.git"
20+
},
21+
"author": "Prabhjot Singh",
22+
"license": "ISC",
23+
"bugs": {
24+
"url": "https://github.com/PrinceS25/StockAlertBot/issues"
25+
},
26+
"homepage": "https://github.com/PrinceS25/StockAlertBot#readme"
1027
}

stores/amazon.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { fileURLToPath } from "url";
22
import { ALARM, OPEN_URL, USER_AGENTS } from '../main.js'
3-
import threeBeeps from "../beep.js"
4-
import sendAlertToWebhooks from "../webhook.js"
5-
import writeErrorToFile from "../writeToFile.js"
3+
import threeBeeps from "../utils/beep.js"
4+
import sendAlertToWebhooks from "../utils/webhook.js"
5+
import writeErrorToFile from "../utils/writeToFile.js"
66
import axios from "axios";
77
import moment from "moment";
88
import DomParser from "dom-parser"; // https://www.npmjs.com/package/dom-parser

stores/antonline.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { fileURLToPath } from "url";
22
import { ALARM, OPEN_URL, USER_AGENTS } from '../main.js'
3-
import threeBeeps from "../beep.js"
4-
import sendAlertToWebhooks from "../webhook.js"
5-
import writeErrorToFile from "../writeToFile.js"
3+
import threeBeeps from "../utils/beep.js"
4+
import sendAlertToWebhooks from "../utils/webhook.js"
5+
import writeErrorToFile from "../utils/writeToFile.js"
66
import axios from "axios";
77
import moment from "moment";
88
import DomParser from "dom-parser"; // https://www.npmjs.com/package/dom-parser

stores/argos.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { fileURLToPath } from "url";
22
import { ALARM, OPEN_URL, USER_AGENTS } from '../main.js'
3-
import threeBeeps from "../beep.js"
4-
import sendAlertToWebhooks from "../webhook.js"
5-
import writeErrorToFile from "../writeToFile.js"
3+
import threeBeeps from "../utils/beep.js"
4+
import sendAlertToWebhooks from "../utils/webhook.js"
5+
import writeErrorToFile from "../utils/writeToFile.js"
66
import axios from "axios";
77
import moment from "moment";
88
import DomParser from "dom-parser"; // https://www.npmjs.com/package/dom-parser

stores/bestbuy.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { fileURLToPath } from "url";
22
import { ALARM, OPEN_URL } from '../main.js'
3-
import threeBeeps from "../beep.js"
4-
import sendAlertToWebhooks from "../webhook.js"
5-
import writeErrorToFile from "../writeToFile.js"
3+
import threeBeeps from "../utils/beep.js"
4+
import sendAlertToWebhooks from "../utils/webhook.js"
5+
import writeErrorToFile from "../utils/writeToFile.js"
66
import axios from "axios";
77
import moment from "moment";
88
import DomParser from "dom-parser"; // https://www.npmjs.com/package/dom-parser

stores/costco.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { fileURLToPath } from "url";
22
import { ALARM, OPEN_URL } from '../main.js'
3-
import threeBeeps from "../beep.js"
4-
import sendAlertToWebhooks from "../webhook.js"
5-
import writeErrorToFile from "../writeToFile.js"
3+
import threeBeeps from "../utils/beep.js"
4+
import sendAlertToWebhooks from "../utils/webhook.js"
5+
import writeErrorToFile from "../utils/writeToFile.js"
66
import axios from "axios";
77
import moment from "moment";
88
import DomParser from "dom-parser"; // https://www.npmjs.com/package/dom-parser

stores/currys.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { fileURLToPath } from "url";
22
import { ALARM, OPEN_URL, USER_AGENTS } from '../main.js'
3-
import threeBeeps from "../beep.js"
4-
import sendAlertToWebhooks from "../webhook.js"
5-
import writeErrorToFile from "../writeToFile.js"
3+
import threeBeeps from "../utils/beep.js"
4+
import sendAlertToWebhooks from "../utils/webhook.js"
5+
import writeErrorToFile from "../utils/writeToFile.js"
66
import axios from "axios";
77
import moment from "moment";
88
import DomParser from "dom-parser"; // https://www.npmjs.com/package/dom-parser

stores/microcenter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { fileURLToPath } from "url";
22
import { ALARM, OPEN_URL, USER_AGENTS } from '../main.js'
3-
import threeBeeps from "../beep.js"
4-
import sendAlertToWebhooks from "../webhook.js"
5-
import writeErrorToFile from "../writeToFile.js"
3+
import threeBeeps from "../utils/beep.js"
4+
import sendAlertToWebhooks from "../utils/webhook.js"
5+
import writeErrorToFile from "../utils/writeToFile.js"
66
import axios from "axios";
77
import moment from "moment";
88
import DomParser from "dom-parser"; // https://www.npmjs.com/package/dom-parser

0 commit comments

Comments
 (0)