Created
November 23, 2017 00:06
-
-
Save matheus-rossi/cf2aa5a036c66ec5ff887d0fded3c45b 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
bot.onText(/\/eventos (.+)/, (msg, match) => { | |
const chatId = msg.chat.id | |
const resp = normalizer(match[1].trim()) | |
const urlTec = `https://www.sympla.com.br/eventos/${resp}?s=tecnologia` | |
axios.get(urlTec).then((response) => { | |
const $ = cheerio.load(response.data) | |
const data = [] | |
$('.event-box-link').each((i, elm) => { | |
data.push({ | |
name: $(elm).children().eq(1).children().first().text(), | |
date: $(elm).children().eq(2).children().eq(1).first().text().trim(), | |
month: $(elm).children().eq(2).children().eq(0).first().text().trim(), | |
place: $(elm).children().eq(3).children().eq(0).first().text().trim(), | |
city: $(elm).children().eq(3).children().eq(1).text().trim() | |
}) | |
}) | |
const finalData = data.map((el) => `Evento: ${el.name} \nData: ${el.date} - ${el.month} \nLocal: ${el.place} \nHorário e Cidade: ${el.city}`) | |
return finalData | |
}).then((data) => { | |
bot.sendMessage(chatId, data.join('\n\n')) | |
}).catch((error) => { | |
console.log(error) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment