Created
April 9, 2015 14:40
-
-
Save evilcos/2f5a47fbf02fe07bd620 to your computer and use it in GitHub Desktop.
Google Fonts Cache to local.
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
#!/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