parsing emoji list great, but now the list is too long! ha
This commit is contained in:
parent
c3fed850b2
commit
e36842dcad
4 changed files with 34 additions and 3581 deletions
1
emojis.json
Normal file
1
emojis.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load diff
|
@ -1,38 +1,39 @@
|
|||
import jsony
|
||||
import strutils
|
||||
import re
|
||||
import httpclient
|
||||
|
||||
type
|
||||
Emoji = tuple
|
||||
emoji: string
|
||||
name: string
|
||||
import emurrjilist
|
||||
|
||||
var emojis: seq[Emoji] = @[]
|
||||
let e_re = re"E[0-9\.]+"
|
||||
|
||||
proc parse(body: string): seq[string] =
|
||||
proc parse(body: string) =
|
||||
for line in body.split("\n"):
|
||||
if line == "" or (line.len > 0 and line[0] == '#'):
|
||||
continue
|
||||
try:
|
||||
let parts = line.split("#")
|
||||
let emo = parts[1].split(e_re)
|
||||
var emoji = (emoji: emo[0], name: emo[1])
|
||||
emoji.emoji = emoji.emoji.strip(chars={' '})
|
||||
emoji.name = emoji.name.strip()
|
||||
var emoji = Emoji()
|
||||
emoji.emoji = emo[0].strip(chars={' '})
|
||||
emoji.name = emo[1].strip()
|
||||
emojis.add(emoji)
|
||||
except:
|
||||
echo getCurrentExceptionMsg()
|
||||
|
||||
proc getUnicodeOrgEmoji(): seq[string] =
|
||||
proc getUnicodeOrgEmoji() =
|
||||
const url = "https://unicode.org/Public/emoji/latest/emoji-test.txt"
|
||||
var client = newHttpClient()
|
||||
let page = client.get(url)
|
||||
parse(page.body)
|
||||
|
||||
proc save(emojis: seq[Emoji]) =
|
||||
let file = "emojis.json"
|
||||
writeFile(file, emojis.toJson())
|
||||
|
||||
proc getEmojis() =
|
||||
let emojis = getUnicodeOrgEmoji()
|
||||
getUnicodeOrgEmoji()
|
||||
save(emojis)
|
||||
|
||||
when isMainModule:
|
||||
getEmojis()
|
||||
|
|
|
@ -14,6 +14,7 @@ requires "nim >= 2.0.0"
|
|||
requires "parsetoml >= 0.7.1"
|
||||
requires "argparse"
|
||||
requires "configparser"
|
||||
requires "jsony"
|
||||
|
||||
task refresh_emoji, "Refresh Emoji Library file":
|
||||
exec "nim c -r src/lib/refresh_emoji.nim"
|
||||
|
|
Loading…
Reference in a new issue