Skip to content

Instantly share code, notes, and snippets.

@liruqi
Created July 10, 2014 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liruqi/5309d08e63de0baf3365 to your computer and use it in GitHub Desktop.
Save liruqi/5309d08e63de0baf3365 to your computer and use it in GitHub Desktop.
Get the names of apple download fonts
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