Skip to content

Instantly share code, notes, and snippets.

@sptndc
Last active March 13, 2020 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sptndc/a20250d3a99e872dffb64e14de123531 to your computer and use it in GitHub Desktop.
Save sptndc/a20250d3a99e872dffb64e14de123531 to your computer and use it in GitHub Desktop.
Whatsapp Emoji Mapper
const axios = require('axios')
const cheerio = require('cheerio')
const fs = require('fs')
const path = require('path')
const emojiList = {}
let key, value
axios.get('https://emojipedia.org/whatsapp/').then(response => {
if (response.status === 200) {
const $ = cheerio.load(response.data)
$('ul.emoji-grid > li').each((index, element) => {
key = $(element).find('img').attr('src')
value = $(element).find('img').attr('src')
if ($(element).hasClass('lazyparent')) {
key = $(element).find('img').data('src')
value = $(element).find('img').data('src')
}
key = key.substring(key.lastIndexOf('/') + 1)
.replace(/^[a-z0-9-]+/, '')
.replace(/_/, '')
.replace(/emoji-modifier-fitzpatrick-type-/, '')
.replace(/1-2_|3_|4_|5_|6_/, '')
.replace(/_1f3fb|_1f3fc|_1f3fd|_1f3fe|_1f3ff/, '')
.replace(/\.png$/, '')
value = value.substring(value.lastIndexOf('/') + 1)
.replace(/^([a-z0-9-]+).*(-type-[0-9-]+).*/, '$1$2')
.replace(/^flag-for-([a-z-]+)/, '$1-flag')
.replace(/_[a-z0-9-.]+$/, '')
.split('-').join('_')
emojiList[key] = value
})
fs.writeFile(
path.resolve('resources', 'js', 'whatsapp-emoji-list.json'),
JSON.stringify(emojiList, null, 4),
error => {
if (error) {
console.log(error)
}
console.log('File successfully written!')
}
)
}
}).catch(error => console.log(error))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment