forked from Pythonity/font-awesome-to-png
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-font-awsome-icons.py
31 lines (26 loc) · 1.02 KB
/
update-font-awsome-icons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sys
import urllib
import BeautifulSoup
# Support Unicode literals with both Python 2 and 3
if sys.version < '3':
import codecs
def u(x):
return codecs.unicode_escape_decode(x)[0]
else:
def u(x):
return x
c = urllib.urlopen("https://fortawesome.github.io/Font-Awesome/cheatsheet/").read()
b = BeautifulSoup.BeautifulSoup(c)
d = {}
for div in b.findAll("div"):
if 1 == len(div.findAll("i")):
fontawsomeChar = div.findAll("i")[0].text
if(len(div.contents) > 2 and fontawsomeChar != ""):
for tag in div.findAll('small'):
tag.replaceWith('')
elements = filter(lambda x: x != '\n' and x != '(alias)', div.findAll(text=True))
elements = map(lambda x: x.strip(), elements)
# print str(elements) + " ----- " + str(len(elements))
fontawsomeChar = fontawsomeChar.replace("", "")
name = str(elements[1]).replace("fa-", "")
print '"'+name+'": ' + 'u("\uf' + fontawsomeChar.replace(";", "") + '"),'