Skip to content

Instantly share code, notes, and snippets.

View matheus-rossi's full-sized avatar
🎯
Data Engineer

Matheus Rossi matheus-rossi

🎯
Data Engineer
View GitHub Profile
const getExchangeRate = (from, to) => {
return axios.get(`http://api.fixer.io/latest?base=${from}`).then((res)=> {
return res.data.rates[to]
})
}
const getCountries = (currencyCode) => {
return axios.get(`https://restcountries.eu/rest/v2/currency/${currencyCode}`).then((res)=> {
return res.data.map((country)=> country.name)
})
}
const convertCurrency = (from, to, amount) => {
let countries
return getCountries(to).then((tempCountries) => {
countries = tempCountries
return getExchangeRate(from, to)
}).then((rate) => {
const exchangedAmount = amount * rate
return `${amount} ${from} is worth ${exchangedAmount} ${to}. ${to} can be used in the following countries: ${countries.join(', ')}`
})
}
const convertCurrencyAlt = async (from, to, amount) => {
const countries = await getCountriesAlt(to)
const rate = await getExchangeRateAlt(from, to)
const exchangedAmount = amount * rate
return `${amount} ${from} is worth ${exchangedAmount} ${to}. ${to} can be used in the following countries: ${countries.join(', ')}`
}
@matheus-rossi
matheus-rossi / crawlModel.js
Created October 1, 2017 23:25
crawler - model works
const arr = [
'h1',
'h2',
'h3'
]
const arr2 = [
'p1',
'p2',
'p3',
var Horseman = require('node-horseman');
var horseman = new Horseman();
horseman
.open('http://www.angeloni.com.br/super/index')
.status()
.evaluate(function(){
const descNode = document.querySelectorAll('.descr a')
const desc = Array.prototype.map.call(descNode, function (t) { return t.textContent })
@matheus-rossi
matheus-rossi / index.js
Created November 18, 2017 12:57
Telegram Bot
const TelegramBot = require('node-telegram-bot-api')
const TOKEN = '123345567:AAABBBCCCDDD1A22RbCdTyoIjYaTek'
const bot = new TelegramBot(TOKEN, { polling: true })
bot.on('new_chat_members', (msg) => {
bot.sendMessage(msg.chat.id, `Olá ${msg.from.first_name}, bem vindo ao Devs SC!! Conte-nos um pouco sobre você, com o que trabalha e onde, se possivel é claro`)
})
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({
const defaultDiacriticsRemovalMap = [{
'base': "A",
'letters': /(A|Ⓐ|A|À|Á|Â|Ầ|Ấ|Ẫ|Ẩ|Ã|Ā|Ă|Ằ|Ắ|Ẵ|Ẳ|Ȧ|Ǡ|Ä|Ǟ|Ả|Å|Ǻ|Ǎ|Ȁ|Ȃ|Ạ|Ậ|Ặ|Ḁ|Ą|Ⱥ|Ɐ|[\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F])/g
}, {
'base': "AA",
'letters': /(Ꜳ|[\uA732])/g
}, {
'base': "AE",
'letters': /(Æ|Ǽ|Ǣ|[\u00C6\u01FC\u01E2])/g
}, {
@matheus-rossi
matheus-rossi / xlsx-to-db.js
Last active June 22, 2022 19:59
xlsx-extract
//Módulo dotenv (variaveis do sistema)
require('dotenv').config({path: '../.env'})
//Modulo para monitorar a pasta com arquivo da programação
const fs = require('fs')
//Modulo para leitura do xlsx
const xlsx = require('node-xlsx')
//Modulo para trabalhar com datas