Created
July 10, 2014 03:51
-
-
Save liruqi/5309d08e63de0baf3365 to your computer and use it in GitHub Desktop.
Get the names of apple download fonts
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
import urllib2 | |
import socket | |
import json | |
import sys | |
from HTMLParser import HTMLParser | |
import requests | |
import argparse | |
import xml.etree.cElementTree as ET | |
url = "http://mesu.apple.com/assets/com_apple_MobileAsset_Font/com_apple_MobileAsset_Font.xml" | |
response = urllib2.urlopen(url, timeout=6) | |
data = response.read() | |
response.close() | |
filehandle = open("com_apple_MobileAsset_Font.xml", "w") | |
filehandle.write(data) | |
filehandle.close() | |
tree = ET.ElementTree(file='com_apple_MobileAsset_Font.xml') | |
root = tree.getroot() | |
fonts = root[0][1] | |
for font in fonts: | |
foundnode = False | |
for node in font: | |
if node.tag == "key" and node.text == "FontInfo": | |
foundnode = True | |
continue | |
if foundnode: | |
foundnode = False | |
for item in node: | |
idx = 0 | |
for leaf in item: | |
if leaf.tag == "key" and leaf.text == "PostScriptFontName": | |
# ET.dump(node[0][idx]) | |
# ET.dump(node[0][idx+1]) | |
print item[idx+1].text | |
idx += 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment