Skip to content

Instantly share code, notes, and snippets.

@demarcusw
Forked from jef/nvidia.js
Created September 21, 2020 00:04
Show Gist options
  • Save demarcusw/4e429b29a8b47f0f8c0bed4391fa0cc6 to your computer and use it in GitHub Desktop.
Save demarcusw/4e429b29a8b47f0f8c0bed4391fa0cc6 to your computer and use it in GitHub Desktop.

Revisions

  1. @jef jef revised this gist Sep 18, 2020. No changes.
  2. @jef jef revised this gist Sep 18, 2020. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion nvidia.js
    Original file line number Diff line number Diff line change
    @@ -30,6 +30,7 @@ async function buy() {
    const links = [
    "https://www.nvidia.com/en-us/geforce/buy/",
    "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3080",
    "https://www.bestbuy.com/site/nvidia-geforce-rtx-3080-10gb-gddr6x-pci-express-4-0-graphics-card-titanium-and-black/6429440.p?skuId=6429440",
    ];
    for (const link of links) {
    await goto(link);
    @@ -41,6 +42,11 @@ async function buy() {
    async function goto(link) {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();

    await page.setUserAgent(
    "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
    );

    page.setViewport({
    width: 1920,
    height: 1080,
    @@ -57,7 +63,7 @@ async function goto(link) {

    console.log(dom);

    if (dom.body.toLowerCase().includes("out of stock")) {
    if (dom.body.toLowerCase().includes("out of stock") || dom.body.toLowerCase().includes("sold out")) {
    console.log("still out of stock, will try again.");
    } else {
    console.log("*** IN STOCK, BUY NOW ***");
  3. @jef jef revised this gist Sep 17, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion nvidia.js
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@ const opn = require("opn");
    const nodemailer = require("nodemailer");

    const timeout = 5000;
    const waitForTimeout = 1000;

    const cartLink =
    "https://store.nvidia.com/store/nvidia/en_US/buy/productID.5438481700/clearCart.yes/nextPage.QuickBuyCartPage";
    @@ -46,7 +47,7 @@ async function goto(link) {
    });

    await page.goto(link);
    await page.waitFor(1000);
    await page.waitFor(waitForTimeout);

    const dom = await page.evaluate(() => {
    return {
  4. @jef jef revised this gist Sep 17, 2020. No changes.
  5. @jef jef revised this gist Sep 17, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions nvidia.js
    Original file line number Diff line number Diff line change
    @@ -77,7 +77,7 @@ async function goto(link) {
    }

    try {
    buy()
    buy();
    } catch (error) {
    buy()
    buy();
    }
  6. @jef jef revised this gist Sep 17, 2020. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions nvidia.js
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@ const puppeteer = require("puppeteer");
    const opn = require("opn");
    const nodemailer = require("nodemailer");

    const timeout = 5000;

    const cartLink =
    "https://store.nvidia.com/store/nvidia/en_US/buy/productID.5438481700/clearCart.yes/nextPage.QuickBuyCartPage";

    @@ -23,8 +25,6 @@ const mailOptions = {
    text: cartLink,
    };

    const timeout = 5000;

    async function buy() {
    const links = [
    "https://www.nvidia.com/en-us/geforce/buy/",
    @@ -77,7 +77,7 @@ async function goto(link) {
    }

    try {
    buy();
    buy()
    } catch (error) {
    buy();
    buy()
    }
  7. @jef jef revised this gist Sep 17, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions nvidia.js
    Original file line number Diff line number Diff line change
    @@ -77,7 +77,7 @@ async function goto(link) {
    }

    try {
    buy().then();
    buy();
    } catch (error) {
    buy().then();
    buy();
    }
  8. @jef jef revised this gist Sep 17, 2020. 1 changed file with 26 additions and 20 deletions.
    46 changes: 26 additions & 20 deletions nvidia.js
    Original file line number Diff line number Diff line change
    @@ -1,30 +1,34 @@
    const puppeteer = require("puppeteer");
    const opn = require("opn");
    const nodemailer = require('nodemailer');
    const nodemailer = require("nodemailer");

    const cartLink = "https://store.nvidia.com/store/nvidia/en_US/buy/productID.5438481700/clearCart.yes/nextPage.QuickBuyCartPage"
    const cartLink =
    "https://store.nvidia.com/store/nvidia/en_US/buy/productID.5438481700/clearCart.yes/nextPage.QuickBuyCartPage";

    const emailUsername = process.env.EMAIL_USERNAME;
    const emailPassword = process.env.EMAIL_PASSWORD;

    const transporter = nodemailer.createTransport({
    service: 'gmail',
    service: "gmail",
    auth: {
    user: '[email protected]',
    pass: 'password'
    }
    user: emailUsername,
    pass: emailPassword,
    },
    });

    const mailOptions = {
    from: '[email protected]',
    to: '[email protected]',
    subject: 'NVIDIA - BUY NOW',
    text: cartLink
    from: emailUsername,
    to: emailUsername,
    subject: "NVIDIA - BUY NOW",
    text: cartLink,
    };

    const timeout = 5000;

    async function buy() {
    const links = [
    "https://www.nvidia.com/en-us/geforce/buy/",
    "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3080"
    "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3080",
    ];
    for (const link of links) {
    await goto(link);
    @@ -58,20 +62,22 @@ async function goto(link) {
    console.log("*** IN STOCK, BUY NOW ***");
    await page.screenshot({ path: `nvidia-${Date.now()}.png` });
    opn(cartLink);
    transporter.sendMail(mailOptions, function(error, info){
    if (error) {
    console.log(error);
    } else {
    console.log('Email sent: ' + info.response);
    }
    });
    if (emailUsername && emailPassword) {
    transporter.sendMail(mailOptions, function (error, info) {
    if (error) {
    console.log(error);
    } else {
    console.log("email sent: " + info.response);
    }
    });
    }
    }

    await browser.close();
    }

    try {
    buy().then();
    } catch(error) {
    } catch (error) {
    buy().then();
    }
    }
  9. @jef jef revised this gist Sep 17, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nvidia.js
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ const transporter = nodemailer.createTransport({
    const mailOptions = {
    from: '[email protected]',
    to: '[email protected]',
    subject: 'NVIDIA, BUY NOW',
    subject: 'NVIDIA - BUY NOW',
    text: cartLink
    };

  10. @jef jef revised this gist Sep 17, 2020. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion nvidia.js
    Original file line number Diff line number Diff line change
    @@ -70,4 +70,8 @@ async function goto(link) {
    await browser.close();
    }

    buy().then();
    try {
    buy().then();
    } catch(error) {
    buy().then();
    }
  11. @jef jef revised this gist Sep 17, 2020. 1 changed file with 26 additions and 1 deletion.
    27 changes: 26 additions & 1 deletion nvidia.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,23 @@
    const puppeteer = require("puppeteer");
    const opn = require("opn");
    const nodemailer = require('nodemailer');

    const cartLink = "https://store.nvidia.com/store/nvidia/en_US/buy/productID.5438481700/clearCart.yes/nextPage.QuickBuyCartPage"

    const transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
    user: '[email protected]',
    pass: 'password'
    }
    });

    const mailOptions = {
    from: '[email protected]',
    to: '[email protected]',
    subject: 'NVIDIA, BUY NOW',
    text: cartLink
    };

    const timeout = 5000;

    @@ -39,7 +57,14 @@ async function goto(link) {
    } else {
    console.log("*** IN STOCK, BUY NOW ***");
    await page.screenshot({ path: `nvidia-${Date.now()}.png` });
    opn("https://store.nvidia.com/store/nvidia/en_US/buy/productID.5438481700/clearCart.yes/nextPage.QuickBuyCartPage");
    opn(cartLink);
    transporter.sendMail(mailOptions, function(error, info){
    if (error) {
    console.log(error);
    } else {
    console.log('Email sent: ' + info.response);
    }
    });
    }

    await browser.close();
  12. @jef jef revised this gist Sep 17, 2020. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion nvidia.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,6 @@ const timeout = 5000;

    async function buy() {
    const links = [
    "https://store.nvidia.com/store/nvidia/en_US/buy/productID.5438481700/clearCart.yes/nextPage.QuickBuyCartPage",
    "https://www.nvidia.com/en-us/geforce/buy/",
    "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3080"
    ];
  13. @jef jef revised this gist Sep 17, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions nvidia.js
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@ const timeout = 5000;

    async function buy() {
    const links = [
    "https://store.nvidia.com/store/nvidia/en_US/buy/productID.5438481700/clearCart.yes/nextPage.QuickBuyCartPage",
    "https://www.nvidia.com/en-us/geforce/buy/",
    "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3080"
    ];
  14. @jef jef revised this gist Sep 17, 2020. 1 changed file with 0 additions and 47 deletions.
    47 changes: 0 additions & 47 deletions nvidia.js
    Original file line number Diff line number Diff line change
    @@ -15,47 +15,6 @@ async function buy() {
    setTimeout(buy, timeout);
    }

    async function goto(link) {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    page.setViewport({
    width: 1920,
    height: 1080,
    });

    await page.goto(link);
    await page.waitFor(1000);

    const dom = await page.evaluate(() => {
    return {
    body: document.body.innerText,
    };
    });

    console.log(dom);

    if (dom.body.toLowerCase().includes("out of stock")) {
    console.log("still out of stock, will try again.");
    } else {
    console.log("*** IN STOCK, BUY NOW ***");
    await page.screenshot({ path: `nvidia-${Date.now()}.png` });
    opn(const puppeteer = require("puppeteer");
    const opn = require("opn");

    const timeout = 5000;

    async function buy() {
    const links = [
    "https://www.nvidia.com/en-us/geforce/buy/",
    "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3080"
    ];
    for (const link of links) {
    await goto(link);
    }

    setTimeout(buy, timeout);
    }

    async function goto(link) {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    @@ -86,10 +45,4 @@ async function goto(link) {
    await browser.close();
    }

    buy().then(););
    }

    await browser.close();
    }

    buy().then();
  15. @jef jef revised this gist Sep 17, 2020. 1 changed file with 48 additions and 1 deletion.
    49 changes: 48 additions & 1 deletion nvidia.js
    Original file line number Diff line number Diff line change
    @@ -39,7 +39,54 @@ async function goto(link) {
    } else {
    console.log("*** IN STOCK, BUY NOW ***");
    await page.screenshot({ path: `nvidia-${Date.now()}.png` });
    opn(link);
    opn(const puppeteer = require("puppeteer");
    const opn = require("opn");

    const timeout = 5000;

    async function buy() {
    const links = [
    "https://www.nvidia.com/en-us/geforce/buy/",
    "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3080"
    ];
    for (const link of links) {
    await goto(link);
    }

    setTimeout(buy, timeout);
    }

    async function goto(link) {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    page.setViewport({
    width: 1920,
    height: 1080,
    });

    await page.goto(link);
    await page.waitFor(1000);

    const dom = await page.evaluate(() => {
    return {
    body: document.body.innerText,
    };
    });

    console.log(dom);

    if (dom.body.toLowerCase().includes("out of stock")) {
    console.log("still out of stock, will try again.");
    } else {
    console.log("*** IN STOCK, BUY NOW ***");
    await page.screenshot({ path: `nvidia-${Date.now()}.png` });
    opn("https://store.nvidia.com/store/nvidia/en_US/buy/productID.5438481700/clearCart.yes/nextPage.QuickBuyCartPage");
    }

    await browser.close();
    }

    buy().then(););
    }

    await browser.close();
  16. @jef jef revised this gist Sep 17, 2020. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions nvidia.js
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,7 @@ const timeout = 5000;
    async function buy() {
    const links = [
    "https://www.nvidia.com/en-us/geforce/buy/",
    "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3080",
    "https://t.co/jm0rrgxkDl?amp=1"
    "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3080"
    ];
    for (const link of links) {
    await goto(link);
  17. @jef jef revised this gist Sep 17, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nvidia.js
    Original file line number Diff line number Diff line change
    @@ -46,4 +46,4 @@ async function goto(link) {
    await browser.close();
    }

    buy().then();
    buy().then();
  18. @jef jef revised this gist Sep 17, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nvidia.js
    Original file line number Diff line number Diff line change
    @@ -39,10 +39,10 @@ async function goto(link) {
    console.log("still out of stock, will try again.");
    } else {
    console.log("*** IN STOCK, BUY NOW ***");
    await page.screenshot({ path: `nvidia-${Date.now()}.png` });
    opn(link);
    }

    await page.screenshot({ path: `nvidia-${Date.now()}.png` });
    await browser.close();
    }

  19. @jef jef revised this gist Sep 17, 2020. No changes.
  20. @jef jef created this gist Sep 17, 2020.
    49 changes: 49 additions & 0 deletions nvidia.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    const puppeteer = require("puppeteer");
    const opn = require("opn");

    const timeout = 5000;

    async function buy() {
    const links = [
    "https://www.nvidia.com/en-us/geforce/buy/",
    "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3080",
    "https://t.co/jm0rrgxkDl?amp=1"
    ];
    for (const link of links) {
    await goto(link);
    }

    setTimeout(buy, timeout);
    }

    async function goto(link) {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    page.setViewport({
    width: 1920,
    height: 1080,
    });

    await page.goto(link);
    await page.waitFor(1000);

    const dom = await page.evaluate(() => {
    return {
    body: document.body.innerText,
    };
    });

    console.log(dom);

    if (dom.body.toLowerCase().includes("out of stock")) {
    console.log("still out of stock, will try again.");
    } else {
    console.log("*** IN STOCK, BUY NOW ***");
    opn(link);
    }

    await page.screenshot({ path: `nvidia-${Date.now()}.png` });
    await browser.close();
    }

    buy().then();