Created
December 19, 2012 15:09
-
-
Save kingkorf/4337353 to your computer and use it in GitHub Desktop.
Google Web-font downloader
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/env python | |
import argparse | |
import urllib2 | |
import sys | |
import re | |
parser = argparse.ArgumentParser(description='Download Google Web-fonts') | |
parser.add_argument('--url', dest='url', help='URL from Google Web-fonts') | |
args = parser.parse_args() | |
url = args.url | |
if url == None: | |
parser.print_help() | |
sys.exit(0) | |
req = urllib2.Request(url) | |
req.add_header('User-agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.101 Safari/537.11') | |
res = urllib2.urlopen(req) | |
css = res.read() | |
urls = re.findall(r"url\(([^\)]+)\)", css) | |
for u in urls: | |
filename = u.split('/')[-1] | |
o = urllib2.urlopen(u) | |
file = open(filename, 'w') | |
file.write(o.read()) | |
file.close() | |
print "Downloaded: " + filename + " from " + u |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment