Skip to content

Instantly share code, notes, and snippets.

@DastanIqbal
Last active August 16, 2020 11:33
Show Gist options
  • Save DastanIqbal/4ad18d173f191ce4d5c6da373a7ec8ec to your computer and use it in GitHub Desktop.
Save DastanIqbal/4ad18d173f191ce4d5c6da373a7ec8ec to your computer and use it in GitHub Desktop.
Generate Android icons.xml file using demo.html Glyph icons
#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