Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created March 7, 2012 04:03
Show Gist options
  • Select an option

  • Save jordanorelli/1990868 to your computer and use it in GitHub Desktop.

Select an option

Save jordanorelli/1990868 to your computer and use it in GitHub Desktop.
get all svgs from the noun project
from os import path
import re
import requests
url_template = "http://thenounproject.com/download/zipped/svg_%d.zip"
base_dir = path.dirname(path.abspath(__file__))
svg_dir = path.join(base_dir, 'svg')
pattern = re.compile(r'<svg.*/svg>', re.DOTALL)
for x in xrange(1, 300):
res = requests.get(url_template % x)
if not res.ok:
print "MISS %d" % x
continue
try:
body = re.search(pattern, res.content).group(0)
with open(path.join(svg_dir, "%d.svg" % x), 'w+') as f:
f.write(body)
print "HIT %d" % x
except AttributeError:
print "PARSE-ERROR %x" % x
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<style>
#noun-container { margin: 20px auto; width: 960px; }
.noun-icon { margin: 20px 0 20px 20px; float: left; width: 100px; height: 100px; }
</style>
</head>
<body>
<div id="noun-container" role="main">
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>')</script>
<script>
// these ones are missing.
var blacklist = [300, 334, 351, 360, 368, 512, 642, 645, 764, 779, 780, 798, 799, 800, 899, 962, 991, 997, 1037, 1048, 1075, 1077, 1102, 1104, 1268, 1271, 1272, 1273, 1274, 1321, 1358, 1359, 1389, 1391, 1404, 1406, 1442];
$(document).ready(function() {
// probably want to start with fewer.
for(var i = 0; i < 1535; i++) {
if($.inArray(i, blacklist) > -1) {
continue;
}
var id = 'noun_' + i;
$('#noun-container').append('<object id="' + id + '" class="noun-icon" data="/svg/' + i + '.svg" type="image/svg+xml" />');
}
});
</script>
</body>
</html>
@jordanorelli
Copy link
Copy Markdown
Author

this... this doesn't really work, does it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment