Last active
August 16, 2020 11:33
-
-
Save DastanIqbal/4ad18d173f191ce4d5c6da373a7ec8ec to your computer and use it in GitHub Desktop.
Generate Android icons.xml file using demo.html Glyph icons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pip3 install bs4 | |
#pip3 install lxml | |
import sys | |
from bs4 import BeautifulSoup as bs | |
separator = "=" | |
file = open("icons.xml",'w') | |
file.write('<?xml version="1.0" encoding="utf-8"?>\n') | |
file.write('<resources>\n') | |
with open(sys.argv[1],'r') as f: | |
contents = f.read() | |
soup = bs(contents, 'lxml') | |
ls = soup.find_all("div",{"class":"glyph fs1"}) | |
for en in ls: | |
iconName = en.find("span",{"class":"mls"}).text.strip().replace("-","_") | |
iconCode = en.find("input",{"class":"unit size1of2"})["value"].strip() | |
file.write(f"""\t<string name="{iconName}" translatable="false">\\u{iconCode}</string>\n""") | |
file.write('</resources>') | |
file.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment