Skip to content

Commit

Permalink
add log for minimum price check skips
Browse files Browse the repository at this point in the history
  • Loading branch information
chapiewsky committed Jun 11, 2019
1 parent b2bd23a commit 9207c07
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
30 changes: 18 additions & 12 deletions src/giveaways.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ const {
checkMinPrice
} = require('./utils');
const sgMail = require('@sendgrid/mail');
var Tesseract = require('tesseract.js');
const Tesseract = require('tesseract.js');
const sqlite = require('./database');
const urlTypes = require('./globals');

let currentGiveawayUrl = '';

/**
* Checks if giveaway has already been entered
* @param {Puppeteer.Page} page
Expand Down Expand Up @@ -353,10 +355,10 @@ async function handleGiveawayResult(page) {
await sgMail.send(msg);
}
//Store that we won
setProcessingCode(urlTypes.WIN, pageUrl);
await setProcessingCode(urlTypes.WIN, currentGiveawayUrl);
} else {
// Store that we lost
setProcessingCode(urlTypes.LOST, pageUrl);
await setProcessingCode(urlTypes.LOST, currentGiveawayUrl);
}
return true;
} catch (error) {
Expand Down Expand Up @@ -525,10 +527,10 @@ async function setProcessingCode(code, giveawayUrl) {
}

/**
* Uses database to deterimine if the page should work like a blacklist page.
* Uses database to determine if the page should work like a blacklist page.
* At this time, it will return true when any value is associated with the page.
* Later, this can be expanded so certain pages can be reprocessed by allowing the code
* and then letting them work. This would be usefull when certain new features that prevented
* and then letting them work. This would be useful when certain new features that prevented
* an entry due to technical requirements.
* @param {String} giveawayUrl The URL that needs to be checked.
* @returns {boolean} true if the page should be skipped or false otherwise.
Expand Down Expand Up @@ -630,16 +632,19 @@ async function enterGiveaways(page, pageNumber) {

let giveawayUrl = await getGiveawayURL(page, i);
if (giveawayUrl.length > 0) {
giveawayUrl = giveawayUrl.substring(0, giveawayUrl.indexOf('?'));
const skippable = await isSkippable(giveawayUrl);
currentGiveawayUrl = giveawayUrl.substring(0, giveawayUrl.indexOf('?'));
const skippable = await isSkippable(currentGiveawayUrl);
if (skippable) {
console.log(
'giveaway ' + i + ' has already been checked per DB record.'
);
await sleep(500);
return;
}
} else {
currentGiveawayUrl = '';
}
console.log('giveaway ' + i + ' url: ' + currentGiveawayUrl);

const noEntryRequired = await page.$x(
`//ul[@class="listing-info-container"]/li[${i}]//a/div[2]/div[2]/span[contains(text(), "No entry requirement")]`
Expand Down Expand Up @@ -676,7 +681,7 @@ async function enterGiveaways(page, pageNumber) {
if (ended) {
console.log('giveaway ' + i + ' ended.');
//Store that the giveaway has ended.
setProcessingCode(urlTypes.ENDED, giveawayUrl);
await setProcessingCode(urlTypes.ENDED, currentGiveawayUrl);
await page.goBack();
return;
}
Expand All @@ -686,7 +691,7 @@ async function enterGiveaways(page, pageNumber) {
if (isAlreadyEntered) {
console.log('giveaway ' + i + ' already entered.');
//Store that the giveaway was already entered.
setProcessingCode(urlTypes.ALREADY, giveawayUrl);
await setProcessingCode(urlTypes.ALREADY, currentGiveawayUrl);
await page.goBack();
return;
} else {
Expand All @@ -697,10 +702,11 @@ async function enterGiveaways(page, pageNumber) {
let priceMatch = await hasCostGreaterThanMinimum(page);
if (!priceMatch) {
console.log(
`giveaway ${i} price smaller than ${
`giveaway ${i} price smaller than $${
process.env.MINIMUM_PRICE
}$.`
}.`
);
await setProcessingCode(urlTypes.MINIMUM_PRICE, currentGiveawayUrl);
await page.goBack();
return;
}
Expand All @@ -722,7 +728,7 @@ async function enterGiveaways(page, pageNumber) {
} else {
console.log('giveaway ' + i + ' cannot be entered.');
//Giveaway cannot be entered
setProcessingCode(urlTypes.CANNOT, giveawayUrl);
await setProcessingCode(urlTypes.CANNOT, currentGiveawayUrl);
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const urlTypes = {
LOST: 'L',
ENDED: 'E',
ALREADY: 'A',
CANNOT: 'C'
CANNOT: 'C',
MINIMUM_PRICE: 'M'
};

// Export the object to be used in this format: `urlTypes.WIN`
Expand Down

0 comments on commit 9207c07

Please sign in to comment.