Skip to content

Commit

Permalink
Remove B&H Photo Video, fix Amazon issues, and add block messages whe…
Browse files Browse the repository at this point in the history
…n not using proxies
  • Loading branch information
Prince25 committed Oct 30, 2021
1 parent 42f008a commit 4a00ac6
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 61 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Currently, the following stores are supported:
* Amazon, with ability to track stock by a particular merchant
* Argos (UK. Does not currently work with proxies)\
For PS5, use the following links. Disc: `https://www.argos.co.uk/product/8349000`, Digital: `https://www.argos.co.uk/product/8349024`
* B&H Photo Video
* Best Buy, including open-box and packages (Does not currently work with proxies)
* Costco (Does not currently work with proxies)
* Currys (UK)
Expand Down Expand Up @@ -200,7 +199,8 @@ To provide monetary support, [donate](https://www.paypal.com/donate?business=3Y9
## Things to work on
* Add more stores
* Newegg search pages
* ~~B&H Photo Video~~
* Best Buy preorder alerts
* ~~B&H Photo Video~~ (no longer supported)
* ~~Ebuyer~~
* ~~Walmart~~
* ~~Gamestop~~
Expand Down
2 changes: 0 additions & 2 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"amazon",
"antonline",
"argos",
"bhphotovideo",
"bestbuy",
"costco",
"currys",
Expand All @@ -37,7 +36,6 @@
"SUPPORTED_PROXY_DOMAINS": [
"amazon",
"antonline",
"bhphotovideo",
"currys",
"ebuyer",
"microcenter",
Expand Down
51 changes: 31 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import amazonFunction from "./stores/amazon.js";
import antonlineFunction from "./stores/antonline.js";
import argosFunction from "./stores/argos.js";
import bestbuyFunction from "./stores/bestbuy.js";
import bhphotovideoFunction from "./stores/bhphotovideo.js";
import costcoFunction from "./stores/costco.js";
import currysFunction from "./stores/currys.js";
import ebuyerFunction from "./stores/ebuyer.js";
Expand All @@ -34,7 +33,6 @@ const storeFunctionMap = {
antonline: antonlineFunction,
argos: argosFunction,
bestbuy: bestbuyFunction,
bhphotovideo: bhphotovideoFunction,
costco: costcoFunction,
currys: currysFunction,
ebuyer: ebuyerFunction,
Expand Down
10 changes: 9 additions & 1 deletion src/stores/amazon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ export default function amazon(html) {
try {
const TITLE_SELECTOR = "#productTitle";
const IMAGE_SELECTOR = "#landingImage";
const IMAGE_BOOK_SELECTOR = "#img-canvas > img";
const INVENTORY_SELECTOR = "#add-to-cart-button";

const $ = cheerio.load(html);
const title = $(TITLE_SELECTOR).text()?.trim();
const image = $(IMAGE_SELECTOR).attr("data-old-hires");
let image = $(IMAGE_SELECTOR).attr("data-old-hires");
let inventory = $(INVENTORY_SELECTOR).attr("value");

if (!image) {
image = $(IMAGE_SELECTOR).attr("src");
if (!image) {
image = $(IMAGE_BOOK_SELECTOR).attr("src");
}
}

if (inventory != undefined) {
inventory = true;
} else if (inventory == undefined) {
Expand Down
25 changes: 0 additions & 25 deletions src/stores/bhphotovideo.js

This file was deleted.

23 changes: 14 additions & 9 deletions src/utils/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const PROXY_BLOCKING_MESSAGES = [
"Are you a human?",
"Help us keep your account safe by clicking on the checkbox below",
"we just need to make sure you're not a robot",
"discuss automated access to Amazon",
];

/*
Expand Down Expand Up @@ -106,15 +107,19 @@ export function fetchPage(url, store, use_proxies, badProxies, retry = false, ge
}
})
.then((html) => {
// If proxy was blocked, add to bad list and retry
if (
use_proxies &&
PROXIES &&
PROXY_BLOCKING_MESSAGES.some((message) => html.includes(message))
) {
toConsole("info", `Proxy, ${proxy}, was blocked! Retrying...`);
badProxies.add(proxy);
return fetchPage(url, store, use_proxies, badProxies, true);
// If request was blocked..
if (PROXY_BLOCKING_MESSAGES.some((message) => html.includes(message))) {
// ..via proxy, add it to bad list and retry
if (use_proxies && PROXIES) {
toConsole("info", `Proxy, ${proxy}, was blocked! Retrying...`);
badProxies.add(proxy);
return fetchPage(url, store, use_proxies, badProxies, true);
}
// Otherwise, Raise error
else {
sourceHTML = html;
throw new Error(`Request to ${store} was blocked!`);
}
}

return retry
Expand Down

0 comments on commit 4a00ac6

Please sign in to comment.