Working on a way to refresh emojis
This commit is contained in:
parent
02a87fce2a
commit
c3fed850b2
3 changed files with 42 additions and 0 deletions
|
@ -3570,3 +3570,4 @@ const emoji_list: seq[string] = @[
|
|||
]
|
||||
proc getEmoji*(): seq[string] =
|
||||
return emoji_list
|
||||
|
||||
|
|
38
src/lib/refresh_emoji.nim
Normal file
38
src/lib/refresh_emoji.nim
Normal file
|
@ -0,0 +1,38 @@
|
|||
import strutils
|
||||
import re
|
||||
import httpclient
|
||||
|
||||
type
|
||||
Emoji = tuple
|
||||
emoji: string
|
||||
name: string
|
||||
|
||||
var emojis: seq[Emoji] = @[]
|
||||
let e_re = re"E[0-9\.]+"
|
||||
|
||||
proc parse(body: string): seq[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()
|
||||
emojis.add(emoji)
|
||||
except:
|
||||
echo getCurrentExceptionMsg()
|
||||
|
||||
proc getUnicodeOrgEmoji(): seq[string] =
|
||||
const url = "https://unicode.org/Public/emoji/latest/emoji-test.txt"
|
||||
var client = newHttpClient()
|
||||
let page = client.get(url)
|
||||
parse(page.body)
|
||||
|
||||
|
||||
proc getEmojis() =
|
||||
let emojis = getUnicodeOrgEmoji()
|
||||
|
||||
when isMainModule:
|
||||
getEmojis()
|
|
@ -14,3 +14,6 @@ requires "nim >= 2.0.0"
|
|||
requires "parsetoml >= 0.7.1"
|
||||
requires "argparse"
|
||||
requires "configparser"
|
||||
|
||||
task refresh_emoji, "Refresh Emoji Library file":
|
||||
exec "nim c -r src/lib/refresh_emoji.nim"
|
||||
|
|
Loading…
Reference in a new issue