Last active
December 25, 2020 20:35
-
-
Save imshaiknasir/076f16ee3811dd4a30bd8e7aaadf55b5 to your computer and use it in GitHub Desktop.
Bot to check PUBGm version from "uptodown" site. Deploy on Heroku. #puppeteer #pubgm #pubg #heroku
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
{ | |
"name": "pupptr", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"start": "node index.js" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"puppeteer": "^5.5.0", | |
"cron": "^1.8.2", | |
"twilio": "^3.54.1" | |
} | |
} |
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
worker: node index.js |
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 CronJob = require('cron').CronJob; | |
const accountSid = ''; // add your own accountSid | |
const authToken = ''; //add your own twilio authToken | |
const client = require('twilio')(accountSid, authToken); | |
const versionsPageUrl = 'https://pubg-mobile.en.uptodown.com/android/versions'; | |
var verionsHistoryArray = ['1.1.0 Nov 10th, 2020'] | |
async function browserConfig() { | |
const browser = await puppeteer.launch({args: ['--no-sandbox'], defaultViewport: null,executablePath:"./node_modules/puppeteer/.local-chromium/linux-818858/chrome-linux/chrome", headless: true }); | |
const page = await browser.newPage(); | |
await page.setDefaultNavigationTimeout(10000) | |
await page.goto(versionsPageUrl, { tiwaitUntil: 'domcontentloaded' }); | |
return page; | |
} | |
async function checkerFunction(page) { | |
await page.reload({ waitUntil: 'domcontentloaded' }) | |
await page.waitForTimeout(10000) | |
// element for app versions present in the table | |
const verTable = await page.$('div#versions-items-list.content div'); | |
await page.waitForTimeout(10000) | |
const appVersion = await (await verTable.getProperty('textContent')).jsonValue(); | |
await page.waitForTimeout(10000) | |
// store the latest pulled data to array | |
verionsHistoryArray.push(appVersion.trim()) | |
// console.log(verionsHistoryArray) | |
// condition to values present inside array | |
if (verionsHistoryArray.length >= 2) { | |
var lastArraryElement = verionsHistoryArray[verionsHistoryArray.length - 1].toString(); | |
var secondLastArrayElement = verionsHistoryArray[verionsHistoryArray.length - 2].toString(); | |
console.log("Comparing: " + lastArraryElement + " ↔️ " + secondLastArrayElement) | |
// now compare the last element with 2nd-last element | |
if (lastArraryElement == secondLastArrayElement) { | |
const messageWrapper = "Last two versions are identical.\n🔄 Waiting for next scheduler RUN..." | |
console.log(messageWrapper) | |
} | |
else { | |
const newVerFound = 'PUBG-Mobile New version found: ' + lastArraryElement + '\n'; | |
await verTable.click(); | |
await page.waitForTimeout(10000) | |
// grab apk download url | |
const downurl = await page.$eval('#detail-download-button', el => el.getAttribute('href')) | |
var downloadDetails = "Download URL: " + downurl + '\n'; | |
const messageWrapper = newVerFound + downloadDetails | |
console.log("Found new version & update sent to Whatsapp\n************************* *********************") | |
client.messages | |
.create({ | |
body: messageWrapper, | |
from: 'whatsapp:+14155230006', // add your twilio number here | |
to: 'whatsapp:+919000000000' //add your WA number here | |
}) | |
.then(message => console.log(message.sid)) | |
.done(); | |
page.goBack({ waitUntil: 'domcontentloaded' }); | |
await page.waitForTimeout(10000) | |
} | |
} | |
else { | |
console.log("Only one element present in Array, can't do version comparision.") | |
} | |
} | |
async function startTracking() { | |
const page = await browserConfig(); | |
let job = new CronJob('0 */5 * * * *', function () { | |
checkerFunction(page); | |
}, null, true, null, null, true); | |
job.start(); | |
} | |
try { | |
startTracking() | |
} catch (error) { | |
console.log(error.name) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment