Last active
August 29, 2015 14:02
-
-
Save tomvon/c57afc01077e91c3ce4c to your computer and use it in GitHub Desktop.
Python script to get google fonts json feed, parse it and print the info. Can be useful for automatically generating stylesheet links for Google Fonts.
This file contains hidden or 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 json | |
import string | |
#Python script to get google fonts json feed, parse it and print the info. | |
#Can be useful for automatically generating stylesheet links for Google Fonts. | |
KEY = 'YOURGOOGLEFONTSAPIKEY' | |
f = urllib2.urlopen('https://www.googleapis.com/webfonts/v1/webfonts?key='+KEY) | |
f = json.loads(f.read()) | |
for item in f['items']: | |
print item['family'] | |
if item['variants']: | |
print len(item['variants']) | |
if len(item['variants']) > 1: | |
variants = [] | |
for var in item['variants']: | |
if var == 'italic': | |
variants.append('400italic') | |
elif var == 'regular': | |
variants.append('400') | |
else: | |
variants.append(var) | |
variants = ':'+','.join(variants) | |
print string.replace(item['family'],' ','+')+variants | |
#Outputs: | |
#ABeeZee | |
#2 | |
#ABeeZee:400,400italic | |
#Abel | |
#1 | |
#Abel:400,400italic | |
#Abril Fatface | |
#1 | |
#... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment