From c3fed850b2f4de4ff75b64ea238f8b33ca65b0a3 Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Fri, 2 Feb 2024 23:03:19 +0000 Subject: [PATCH] Working on a way to refresh emojis --- src/lib/emurrjilist.nim | 1 + src/lib/refresh_emoji.nim | 38 ++++++++++++++++++++++++++++++++++++++ wm_tools.nimble | 3 +++ 3 files changed, 42 insertions(+) create mode 100644 src/lib/refresh_emoji.nim diff --git a/src/lib/emurrjilist.nim b/src/lib/emurrjilist.nim index 13994b3..07dd793 100644 --- a/src/lib/emurrjilist.nim +++ b/src/lib/emurrjilist.nim @@ -3570,3 +3570,4 @@ const emoji_list: seq[string] = @[ ] proc getEmoji*(): seq[string] = return emoji_list + diff --git a/src/lib/refresh_emoji.nim b/src/lib/refresh_emoji.nim new file mode 100644 index 0000000..81f2fce --- /dev/null +++ b/src/lib/refresh_emoji.nim @@ -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() diff --git a/wm_tools.nimble b/wm_tools.nimble index acddde3..80e6fc0 100644 --- a/wm_tools.nimble +++ b/wm_tools.nimble @@ -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"