Skip to content

Instantly share code, notes, and snippets.

@evilcos
Created April 9, 2015 14:40
Show Gist options
  • Save evilcos/2f5a47fbf02fe07bd620 to your computer and use it in GitHub Desktop.
Save evilcos/2f5a47fbf02fe07bd620 to your computer and use it in GitHub Desktop.
Google Fonts Cache to local.
#!/usr/bin/python
# encoding=utf-8
"""Google Fonts Cache.
evilcos.me
2015/4/9
"""
import os
import re
import sys
import urllib
import urllib2
def get_font_urls(_file):
urls = []
f = open(_file)
ll = f.readlines()
f.close()
p = re.compile('url\(([^)]*)\)')
for l in ll:
r = re.findall(p, l)
if r:
urls.append(r[0])
return list(set(urls))
def download(url):
file_name = url.split('/')[-1]
print(url, os.getcwd() + '/' + file_name)
urllib.urlretrieve(url, file_name)
if __name__ == '__main__':
_file = sys.argv[1]
urls = get_font_urls(_file)
for url in urls:
download(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment