Last active
July 29, 2022 15:28
-
-
Save jef/96fd50c6fe3eedc1bdf52585eac2b3c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require("puppeteer"); | |
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"; | |
const emailUsername = process.env.EMAIL_USERNAME; | |
const emailPassword = process.env.EMAIL_PASSWORD; | |
const transporter = nodemailer.createTransport({ | |
service: "gmail", | |
auth: { | |
user: emailUsername, | |
pass: emailPassword, | |
}, | |
}); | |
const mailOptions = { | |
from: emailUsername, | |
to: emailUsername, | |
subject: "NVIDIA - BUY NOW", | |
text: cartLink, | |
}; | |
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); | |
} | |
setTimeout(buy, timeout); | |
} | |
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, | |
}); | |
await page.goto(link); | |
await page.waitFor(waitForTimeout); | |
const dom = await page.evaluate(() => { | |
return { | |
body: document.body.innerText, | |
}; | |
}); | |
console.log(dom); | |
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 ***"); | |
await page.screenshot({ path: `nvidia-${Date.now()}.png` }); | |
opn(cartLink); | |
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(); | |
} catch (error) { | |
buy(); | |
} |
Does anyone have a better way to check for stock? I was sending a get request to
https://api-prod.nvidia.com/direct-sales-shop/DR/products/en_us/USD/5438481600
which would return a json response which would tell you inventory status, but now it doesn't work so well (error 503 - gateway times out).Nvidia's own website makes the same website and now it fails there too, but eventually after a while the out of stock button pops up on their site. Do you guys think their website is setup so that if the request fails the out of stock button shows up? Or is their a better way to check for stock?
import requests url = "https://api-prod.nvidia.com/direct-sales-shop/DR/products/en_us/USD/5438481600" payload = {} headers = { 'authority': 'api-prod.nvidia.com', 'accept': 'application/json, text/javascript, */*; q=0.01', 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36', 'dnt': '1', 'origin': 'https://www.nvidia.com', 'sec-fetch-site': 'same-site', 'sec-fetch-mode': 'cors', 'sec-fetch-dest': 'empty', 'referer': 'https://www.nvidia.com/en-us/geforce/graphics-cards/30-series/rtx-3090/', 'accept-language': 'en-CA,en-GB;q=0.9,en-US;q=0.8,en;q=0.7' } response = requests.request("GET", url, headers=headers, data = payload) print(response.text.encode('utf8'))
This should help:
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
import requests
import json
payload = {}
headers = {
'authority': 'api-prod.nvidia.com',
'accept': 'application/json, text/javascript, */*; q=0.01',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',
'dnt': '1',
'origin': 'https://www.nvidia.com',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://www.nvidia.com/en-us/geforce/graphics-cards/30-series/rtx-3090/',
'accept-language': 'en-CA,en-GB;q=0.9,en-US;q=0.8,en;q=0.7'
}
url = "https://api-prod.nvidia.com/direct-sales-shop/DR/products/en_us/USD/5438481700"
response = requests.request("GET", url, headers=headers, data = payload)
/* print(response.json()) -- you can use this to look at the full dict */
jsonResponse = response.json()
for url in jsonResponse["products"]["product"]:
print(" PRODUCT NAME: ", url["displayName"], '\n', "IN STOCK?: ", url["inventoryStatus"]["productIsInStock"].upper(), '\n', "PRODUCT STATUS: ", url["inventoryStatus"]["status"], '\n', "PRICE: ", url["pricing"]["formattedListPrice"])
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this help?
{
"en-us": {
"rtx-3090": "5438481600",
"rtx-3080": "5438481700",
"rtx-3070": null,
"titan-rtx": "5254456900",
"rtx-2080-super": "5335703700",
"rtx-2070-super": "5394901600",
"rtx-2060-super": "5394902900",
"expensive-shirt": "5444021500"
},
"fr-fr": {
"rtx-3090": "5438761500",
"rtx-3080": "5438795200",
"rtx-3070": null,
"titan-rtx": "5256301100",
"rtx-2080-super": "5336531100",
"rtx-2070-super": "5394901900",
"rtx-2060-super": "5394903200",
"expensive-shirt": "5444021500"
},
"de-de": {
"rtx-3090": "5438761400",
"rtx-3080": "5438792300",
"rtx-3070": null,
"titan-rtx": "5256301000",
"rtx-2080-super": "5335703700",
"rtx-2070-super": "5394901600",
"rtx-2060-super": "5394902900",
"expensive-shirt": "5444021500"
},
"en-gb": {
"rtx-3090": "5438792700",
"rtx-3080": "5438792800",
"rtx-3070": null,
"titan-rtx": "5256301200",
"rtx-2080-super": "5336531200",
"rtx-2070-super": "5394902000",
"rtx-2060-super": "5394903300",
"expensive-shirt": "5444021500"
},
"es-es": {
"rtx-3090": "5438794700",
"rtx-3080": "5438794800",
"rtx-3070": null,
"titan-rtx": "5256301400",
"rtx-2080-super": "5336531400",
"rtx-2070-super": "5394901700",
"rtx-2060-super": "5394903000",
"expensive-shirt": "5444021500"
},
"it-it": {
"rtx-3090": "5438796100",
"rtx-3080": "5438796200",
"rtx-3070": null,
"titan-rtx": "5256302000",
"rtx-2080-super": "5336532000",
"rtx-2070-super": "5394902100",
"rtx-2060-super": "5394903400",
"expensive-shirt": "5444021500"
},
"pl-pl": {
"rtx-3090": "5438797600",
"rtx-3080": "5438797700",
"rtx-3070": null,
"titan-rtx": "5256301600",
"rtx-2080-super": "5336531600",
"rtx-2070-super": "5394902300",
"rtx-2060-super": "5394903700",
"expensive-shirt": "5444021500"
},
"nb-no": {
"rtx-3090": "5438797100",
"rtx-3080": "5438797200",
"rtx-3070": null,
"titan-rtx": "5256301700",
"rtx-2080-super": "5336531700",
"rtx-2070-super": "5394902600",
"rtx-2060-super": "5394903600",
"expensive-shirt": "5444021500"
},
"sv-se": {
"rtx-3090": "5438761600",
"rtx-3080": "5438798100",
"rtx-3070": null,
"titan-rtx": "5256301300",
"rtx-2080-super": "5336531300",
"rtx-2070-super": "5394902500",
"rtx-2060-super": "5394903900",
"expensive-shirt": "5444021500"
},
"da-dk": {
"rtx-3090": "5438793200",
"rtx-3080": "5438793300",
"rtx-3070": null,
"titan-rtx": "5256301800",
"rtx-2080-super": "5336531800",
"rtx-2070-super": "5394901800",
"rtx-2060-super": "5394903100",
"expensive-shirt": "5444021500"
},
"fr-be": {
"rtx-3090": "5438795600",
"rtx-3080": "5438795700",
"rtx-3070": null,
"titan-rtx": "5256301500",
"rtx-2080-super": "5336531500",
"rtx-2070-super": "5336534300",
"rtx-2060-super": "5394902700",
"expensive-shirt": "5444021500"
},
"de-at": {
"rtx-3090": "5444941400",
"rtx-3080": "5440853700",
"rtx-3070": null,
"titan-rtx": "5256301000",
"rtx-2080-super": "5335703700",
"rtx-2070-super": "5394901600",
"rtx-2060-super": "5394902900",
"expensive-shirt": "5444021500"
},
"cs-cz": {
"rtx-3090": "5438793600",
"rtx-3080": "5438793800",
"rtx-3070": null,
"titan-rtx": "5256301900",
"rtx-2080-super": "5336531900",
"rtx-2070-super": "5394901500",
"rtx-2060-super": "5394902800",
"expensive-shirt": "5444021500"
},
"fi-fi": {
"rtx-3090": "5438793200",
"rtx-3080": "5438793300",
"rtx-3070": null,
"titan-rtx": "5256301800",
"rtx-2080-super": "5336531800",
"rtx-2070-super": "5394901800",
"rtx-2060-super": "5394903100",
"expensive-shirt": "5444021500"
},
"nl-nl": {
"rtx-3090": "5438796600",
"rtx-3080": "5438796700",
"rtx-3070": null,
"titan-rtx": "5256302100",
"rtx-2080-super": "5336532100",
"rtx-2070-super": "5394902200",
"rtx-2060-super": "5394903500",
"expensive-shirt": "5444021500"
}
}