parsing emoji list great, but now the list is too long! ha

This commit is contained in:
Paul Wilde 2024-02-02 23:15:27 +00:00
parent c3fed850b2
commit e36842dcad
4 changed files with 34 additions and 3581 deletions

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

View file

@ -1,38 +1,39 @@
import jsony
import strutils import strutils
import re import re
import httpclient import httpclient
import emurrjilist
type
Emoji = tuple
emoji: string
name: string
var emojis: seq[Emoji] = @[] var emojis: seq[Emoji] = @[]
let e_re = re"E[0-9\.]+" let e_re = re"E[0-9\.]+"
proc parse(body: string): seq[string] = proc parse(body: string) =
for line in body.split("\n"): for line in body.split("\n"):
if line == "" or (line.len > 0 and line[0] == '#'): if line == "" or (line.len > 0 and line[0] == '#'):
continue continue
try: try:
let parts = line.split("#") let parts = line.split("#")
let emo = parts[1].split(e_re) let emo = parts[1].split(e_re)
var emoji = (emoji: emo[0], name: emo[1]) var emoji = Emoji()
emoji.emoji = emoji.emoji.strip(chars={' '}) emoji.emoji = emo[0].strip(chars={' '})
emoji.name = emoji.name.strip() emoji.name = emo[1].strip()
emojis.add(emoji) emojis.add(emoji)
except: except:
echo getCurrentExceptionMsg() echo getCurrentExceptionMsg()
proc getUnicodeOrgEmoji(): seq[string] = proc getUnicodeOrgEmoji() =
const url = "https://unicode.org/Public/emoji/latest/emoji-test.txt" const url = "https://unicode.org/Public/emoji/latest/emoji-test.txt"
var client = newHttpClient() var client = newHttpClient()
let page = client.get(url) let page = client.get(url)
parse(page.body) parse(page.body)
proc save(emojis: seq[Emoji]) =
let file = "emojis.json"
writeFile(file, emojis.toJson())
proc getEmojis() = proc getEmojis() =
let emojis = getUnicodeOrgEmoji() getUnicodeOrgEmoji()
save(emojis)
when isMainModule: when isMainModule:
getEmojis() getEmojis()

View file

@ -14,6 +14,7 @@ requires "nim >= 2.0.0"
requires "parsetoml >= 0.7.1" requires "parsetoml >= 0.7.1"
requires "argparse" requires "argparse"
requires "configparser" requires "configparser"
requires "jsony"
task refresh_emoji, "Refresh Emoji Library file": task refresh_emoji, "Refresh Emoji Library file":
exec "nim c -r src/lib/refresh_emoji.nim" exec "nim c -r src/lib/refresh_emoji.nim"