Created
October 11, 2022 00:24
-
-
Save juanigallo/d6a0b986ffc36b8eceea7eba402b2d62 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 axios = require("axios"); | |
const url = | |
"https://www.apple.com/shop/pickup-message-recommendations?mts.0=regular&mts.1=compact&cppart=UNLOCKED/US&searchNearby=true&store=R623&product=MQ933LL/A"; | |
let lastMessageSend = 0; | |
const botId = ""; | |
const chatId = ""; | |
const jsonMap = { | |
"MQ003LL/A": "Silver 128GB", | |
"MQ0X3LL/A": "Silver 256GB", | |
"MQ1U3LL/A": "Silver 512GB", | |
"MQ2L3LL/A": "Silver 1TB", | |
"MQ0E3LL/A": "Deep purple 128GB", | |
"MQ1D3LL/A": "Deep purple 256GB", | |
"MQ273LL/A": "Deep purple 512GB", | |
"MQ303LL/A": "Deep purple 1TB", | |
"MQ063LL/A": "Gold 128GB", | |
"MQ163LL/A": "Gold 256GB", | |
"MQ213LL/A": "Gold 512GB", | |
"MQ2T3LL/A": "Gold 1TB", | |
"MPXT3LL/A": "Space black 128GB", | |
"MQ0N3LL/A": "Space black 256GB", | |
"MQ1K3LL/A": "Space black 512GB", | |
"MQ2E3LL/A": "Space black 1TB 1500USD", | |
}; | |
setInterval(async () => { | |
const apple = await axios.get(url); | |
const baseUrl = | |
"https://www.apple.com/shop/buy-iphone/iphone-14-pro/6.1-inch-display-128gb-deep-purple-unlocked"; | |
console.log( | |
apple.data.body.PickupMessage.recommendedProducts.length == 0 | |
? "No hay stock" | |
: apple.data.body.PickupMessage.recommendedProducts | |
); | |
if ( | |
apple.data.body.PickupMessage.recommendedProducts.length > 0 && | |
Date.now() - lastMessageSend > 30000 | |
) { | |
lastMessageSend = Date.now(); | |
apple.data.body.PickupMessage.recommendedProducts.forEach((item) => { | |
sendTelegramMessage(`${jsonMap[item]} | ${baseUrl}`); | |
}); | |
} | |
}, 1000); | |
function sendTelegramMessage(message) { | |
const telegramMsg = encodeURIComponent(message); | |
const url = `https://api.telegram.org/${botId}/sendMessage?chat_id=${chatId}&text=${telegramMsg}`; | |
axios.get(url); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment