Skip to content

Commit 1cbbc43

Browse files
committed
Add AntOnline Store
1 parent 3f7f505 commit 1cbbc43

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ Enter the product URLs and set how often you want the program to check if those
1111
> What stores/wesbites are supported?
1212
1313
Currently, the following stores are supported:
14+
* AntOnline
1415
* Amazon (Fails at low interval rates)
15-
* Best Buy
16+
* Best Buy (including open-box)
1617
* Costco
1718
* Microcenter
1819
* Newegg
@@ -39,9 +40,10 @@ Currently, the following stores are supported:
3940

4041
### Things to work on
4142
* Add more stores
42-
* ~~Newegg~~
4343
* Walmart
4444
* Gamestop
45+
* ~~Newegg~~
46+
* ~~AntOnline~~
4547
* Add GUI - Make it easier to use
4648
* Add color to console
4749
* ~~Initially create seperation between intervals for Amazon items~~

main.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import antonline from './stores/antonline.js'
12
import amazon from './stores/amazon.js'
23
import bestbuy from './stores/bestbuy.js'
34
import costco from './stores/costco.js'
@@ -18,7 +19,8 @@ const URLS = [
1819
"https://www.newegg.com/amd-ryzen-9-5900x/p/N82E16819113664?Item=N82E16819113664",
1920
"https://www.newegg.com/asus-geforce-rtx-3080-rog-strix-rtx3080-o10g-gaming/p/N82E16814126457",
2021
"https://www.newegg.com/asus-geforce-rtx-3080-tuf-rtx3080-o10g-gaming/p/N82E16814126452",
21-
"https://www.newegg.com/p/N82E16868110292"
22+
"https://www.newegg.com/p/N82E16868110292",
23+
"https://www.antonline.com/Sony/Electronics/Gaming_Devices/Gaming_Consoles/1413553",
2224
]
2325

2426
// How often to check for products. Too often may be dangerous, especially for Amazon.
@@ -112,6 +114,10 @@ URLS.forEach(url => {
112114
}
113115

114116
switch(storeName) {
117+
case 'antonline':
118+
checkStore(antonline, url);
119+
break;
120+
115121
case 'amazon':
116122
amazonItems.push(new amazonItem(url));
117123
break;

stores/antonline.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { fileURLToPath } from "url";
2+
import fs from "fs";
3+
import threeBeeps from "../beep.js"
4+
import axios from "axios";
5+
import moment from "moment";
6+
import DomParser from "dom-parser"; // https://www.npmjs.com/package/dom-parser
7+
8+
9+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
10+
let interval = {
11+
unit: 'seconds', // seconds, m: minutes, h: hours
12+
value: 5
13+
}
14+
let url = 'https://www.antonline.com/Sony/Electronics/Gaming_Devices/Gaming_Consoles/1413553'
15+
antonline(url, interval);
16+
}
17+
18+
19+
let firstRun = new Set();
20+
export default async function antonline(url, interval) {
21+
try {
22+
var res = await axios.get(url);
23+
if (res && res.status === 200) {
24+
let parser = new DomParser();
25+
let doc = parser.parseFromString(res.data, 'text/html');
26+
let title = doc.getElementsByClassName('title')[0].innerHTML.slice(0, 150)
27+
let inventory = doc.getElementsByClassName('uk-button uk-button-primary add_to_cart')
28+
29+
if (inventory && inventory.length > 0) inventory = inventory[0].textContent
30+
if (inventory && inventory.length == 0 && !firstRun.has(url)) {
31+
console.info(moment().format('LTS') + ': "' + title + '" not in stock at AntOnline. Will keep retrying every', interval.value, interval.unit)
32+
firstRun.add(url)
33+
}
34+
else if (inventory && inventory == 'Add to Cart') {
35+
threeBeeps();
36+
console.info(moment().format('LTS') + ': ***** In Stock at AntOnline *****: ', title);
37+
console.info(url);
38+
}
39+
} else {
40+
console.info(moment().format('LTS') + ': Error occured checking ' + title + '. Retrying in', interval.value, interval.unit)
41+
}
42+
43+
} catch (e) {
44+
console.error('Unhandled error. Written to logAntOnline.log')
45+
fs.writeFile('logAntOnline.log', e, function(err, result) {
46+
if(err) console.error('File write error: ', err);
47+
});
48+
}
49+
};

0 commit comments

Comments
 (0)