diff options
Diffstat (limited to 'emoji-updater/emoji-updater.py')
-rwxr-xr-x | emoji-updater/emoji-updater.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/emoji-updater/emoji-updater.py b/emoji-updater/emoji-updater.py new file mode 100755 index 0000000..a0293c7 --- /dev/null +++ b/emoji-updater/emoji-updater.py @@ -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 |