Add emoji-updater script
* Exports emoji list from unicode.org in LatinIME compatible xml format Change-Id: I6b86ac3253ee775c0c1c206ac62bf34a8f317093
This commit is contained in:
30
emoji-updater/emoji-updater.py
Executable file
30
emoji-updater/emoji-updater.py
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
|
||||
import requests
|
||||
from lxml import etree
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit(f'usage: {sys.argv[0]} [url|https://unicode.org/emoji/charts-12.0/full-emoji-list.html]')
|
||||
|
||||
url = sys.argv[1]
|
||||
req = requests.get(url=url)
|
||||
|
||||
parser = etree.HTMLParser(recover=True, encoding='utf-8')
|
||||
doc = etree.fromstring(text=req.content, parser=parser)
|
||||
|
||||
for tr in doc.xpath('.//tr'):
|
||||
mediumhead = tr.xpath('.//th[@class="mediumhead"]/a')
|
||||
|
||||
if len(mediumhead) > 0:
|
||||
print(f' <!-- {mediumhead[0].text} -->')
|
||||
continue
|
||||
|
||||
code = tr.xpath('.//td[@class="code"]/a')
|
||||
|
||||
if len(code) > 0:
|
||||
codes = ','.join([x[2:] for x in code[0].text.split()])
|
||||
print(f' <item>{codes}</item>')
|
||||
continue
|
||||
Reference in New Issue
Block a user