mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 04:07:36 +00:00
Update index.js (#9)
Created multiple oos text checks by changing oosText to array... Fixed bug that opened the wrong link when item is in stock. Co-authored-by: Ion Caza <contact@johncaza.com>
This commit is contained in:
+20
-12
@@ -35,16 +35,15 @@ const mailOptions = {
|
|||||||
async function buy() {
|
async function buy() {
|
||||||
const links = [
|
const links = [
|
||||||
{ name: "nvidia.com", url: "https://www.nvidia.com/en-us/geforce/buy/", oosText: "out of stock" }
|
{ name: "nvidia.com", url: "https://www.nvidia.com/en-us/geforce/buy/", oosText: "out of stock" }
|
||||||
,{ name: "nvidia.com 2", url: "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3080", oosText: "out of stock" }
|
,{ name: "nvidia.com 2", url: "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3080", oosText: ["out of stock"] }
|
||||||
,{ name: "bestbuy.com", url: "https://www.bestbuy.com/site/nvidia-geforce-rtx-3080-10gb-gddr6x-pci-express-4-0-graphics-card-titanium-and-black/6429440.p?skuId=6429440", oosText: "sold out" }
|
,{ name: "bestbuy.com", url: "https://www.bestbuy.com/site/nvidia-geforce-rtx-3080-10gb-gddr6x-pci-express-4-0-graphics-card-titanium-and-black/6429440.p?skuId=6429440", oosText: ["sold out"] }
|
||||||
,{ name: "newegg.com EVGA BLACK GAMING", url: "https://www.newegg.com/evga-geforce-rtx-3080-10g-p5-3881-kr/p/N82E16814487522", oosText: "auto notify" }
|
,{ name: "newegg.com EVGA BLACK GAMING", url: "https://www.newegg.com/evga-geforce-rtx-3080-10g-p5-3881-kr/p/N82E16814487522", oosText: ["auto notify","out of stock"] }
|
||||||
,{ name: "newegg.com MSI VENTUS", url: "https://www.newegg.com/msi-geforce-rtx-3080-rtx-3080-ventus-3x-10g/p/N82E16814137600", oosText: "auto notify" }
|
,{ name: "newegg.com MSI VENTUS", url: "https://www.newegg.com/msi-geforce-rtx-3080-rtx-3080-ventus-3x-10g/p/N82E16814137600", oosText: ["auto notify","out of stock"] }
|
||||||
,{ name: "bestbuy.com GIGABYTE BLACK", url: "https://www.bestbuy.com/site/gigabyte-geforce-rtx-3080-10g-gddr6x-pci-express-4-0-graphics-card-black/6430620.p?acampID=0&cmp=RMX&loc=Hatch&ref=198&skuId=6430620", oosText: "sold out" }
|
,{ name: "bestbuy.com GIGABYTE BLACK", url: "https://www.bestbuy.com/site/gigabyte-geforce-rtx-3080-10g-gddr6x-pci-express-4-0-graphics-card-black/6430620.p?acampID=0&cmp=RMX&loc=Hatch&ref=198&skuId=6430620", oosText: ["sold out"] }
|
||||||
,{ name: "B&H GIGABYTE BLACK", url: "https://www.bhphotovideo.com/c/product/1593333-REG/gigabyte_gv_n3080gaming_oc_10gd_geforce_rtx_3080_gaming.html?SID=s1600391647213ytuua52439", oosText: "notify when available" }
|
,{ name: "B&H GIGABYTE BLACK", url: "https://www.bhphotovideo.com/c/product/1593333-REG/gigabyte_gv_n3080gaming_oc_10gd_geforce_rtx_3080_gaming.html?SID=s1600391647213ytuua52439", oosText: ["notify when available"] }
|
||||||
,{ name: "newegg.com EVGA ARGB LED iCX3", url: "https://www.newegg.com/evga-geforce-rtx-3080-10g-p5-3883-kr/p/N82E16814487521", oosText: "auto notify" }
|
,{ name: "newegg.com EVGA ARGB LED iCX3", url: "https://www.newegg.com/evga-geforce-rtx-3080-10g-p5-3883-kr/p/N82E16814487521", oosText: ["auto notify","out of stock"] }
|
||||||
,{ name: "newegg.com EVGA XC3 ULTRA GAMING", url: "https://www.newegg.com/evga-geforce-rtx-3080-10g-p5-3885-kr/p/N82E16814487520", oosText: "auto notify" }
|
,{ name: "newegg.com EVGA XC3 ULTRA GAMING", url: "https://www.newegg.com/evga-geforce-rtx-3080-10g-p5-3885-kr/p/N82E16814487520", oosText: ["auto notify","out of stock"] }
|
||||||
,{ name: "newegg.com ASUS TUF", url: "https://www.newegg.com/asus-geforce-rtx-3080-tuf-rtx3080-10g-gaming/p/N82E16814126453", oosText: "auto notify" }
|
,{ name: "newegg.com ASUS TUF", url: "https://www.newegg.com/asus-geforce-rtx-3080-tuf-rtx3080-10g-gaming/p/N82E16814126453", oosText: ["auto notify","out of stock"] }
|
||||||
|
|
||||||
]
|
]
|
||||||
for (const link of links) {
|
for (const link of links) {
|
||||||
await goto(link)
|
await goto(link)
|
||||||
@@ -75,12 +74,12 @@ async function goto(link) {
|
|||||||
|
|
||||||
console.log(dom)
|
console.log(dom)
|
||||||
|
|
||||||
if (dom.body.toLowerCase().includes(link.oosText.toLowerCase()) ) {
|
if (isOutOfStock(dom.body, link.oosText)) {
|
||||||
console.log(link.name + " is still out of stock... Attempting next link.")
|
console.log(link.name + " is still out of stock... Attempting next link.")
|
||||||
} else {
|
} else {
|
||||||
console.log("*** IN STOCK AT " + link.name.toUpperCase() + ", BUY NOW ***");
|
console.log("*** IN STOCK AT " + link.name.toUpperCase() + ", BUY NOW ***");
|
||||||
await page.screenshot({ path: `nvidia-${Date.now()}.png` });
|
await page.screenshot({ path: `nvidia-${Date.now()}.png` });
|
||||||
opn(cartLink);
|
opn(link.url);
|
||||||
if (emailUsername && emailPassword) {
|
if (emailUsername && emailPassword) {
|
||||||
transporter.sendMail(mailOptions, function (error, info) {
|
transporter.sendMail(mailOptions, function (error, info) {
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -95,6 +94,15 @@ async function goto(link) {
|
|||||||
await browser.close()
|
await browser.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isOutOfStock(domText, oosTextArray) {
|
||||||
|
domText = domText.toLowerCase();
|
||||||
|
var result = false;
|
||||||
|
for(var text of oosTextArray) {
|
||||||
|
result = domText.includes(text.toLowerCase());
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
buy().then();
|
buy().then();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user