update v2
This commit is contained in:
parent
e52ceb8b18
commit
66b2369476
7 changed files with 10104 additions and 9530 deletions
47
update-emojis.js
Normal file
47
update-emojis.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
const _ = require('lodash')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const request = require('request')
|
||||
const randomUa = require('random-ua')
|
||||
|
||||
// get the latest github version
|
||||
request({
|
||||
url: 'https://api.github.com/emojis',
|
||||
headers: {
|
||||
'User-Agent': randomUa.generate(),
|
||||
},
|
||||
json: true,
|
||||
}, function (error, response, json) {
|
||||
if (response.statusCode === 304) { return }
|
||||
if (error || !_.isObject(json)) {
|
||||
console.error('Failded to download Github emojis.')
|
||||
console.log(error, response, json)
|
||||
return
|
||||
}
|
||||
|
||||
const latestEmojis = Object.keys(json).reduce((emojis, name) => {
|
||||
emojis[name] = { src: json[name] }
|
||||
|
||||
const match = /\/unicode\/(\S+)\./.exec(json[name])
|
||||
if (match) {
|
||||
emojis[name].codepoints = match[1].split('-')
|
||||
}
|
||||
|
||||
return emojis
|
||||
}, {})
|
||||
|
||||
const emojis = _.assign({}, require('./emojis.json'), latestEmojis)
|
||||
|
||||
// update local backup
|
||||
fs.writeFile(
|
||||
path.join(__dirname, 'emojis.json'),
|
||||
JSON.stringify(emojis, null, ' '),
|
||||
function (err) {
|
||||
if (err) {
|
||||
console.warn(err)
|
||||
} else {
|
||||
console.log(`Update ${Object.keys(emojis).length} emojis`)
|
||||
}
|
||||
},
|
||||
)
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue