Skip to content

Instantly share code, notes, and snippets.

@talos
Forked from jordanorelli/get_nouns.py
Created March 7, 2012 16:16
Show Gist options
  • Save talos/1994133 to your computer and use it in GitHub Desktop.
Save talos/1994133 to your computer and use it in GitHub Desktop.
get all svgs from the noun project, draw them all asynchronously with pan & zoom
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>
#drawn { position: absolute; left: 10px; top: 10px; font-family: sans-serif; font-size: .5em; }
#noun-container { margin: 20px auto; width: 960px; height: 960px; }
/* .noun-icon { margin: 20px 0 20px 20px; float: left; width: 100px; height: 100px; } */
</style>
</head>
<body>
<div id="drawn"></div>
<svg id="noun-container" role="main" >
<g id="viewport">
</g>
</svg>
<script src="http://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 src="http://talos.github.com/jquery-svgpan/jquery-svgpan.js"></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() {
var numNouns = 1445, // who you callin numnouns numnouns
width = 2400,
nounWidth = 120,
nounHeight = 120,
nounsPerLine = width / nounWidth,
$viewport = $('g#viewport'),
$drawn = $('#drawn'),
load = function (i) {
$.get('svg/' + i + '.svg').done( function(response) {
var x = (i % nounsPerLine) * nounWidth,
y = ((i - (i % nounsPerLine)) / nounsPerLine) * nounHeight,
$svg = $(response).find('svg').attr({
'x' : x,
'y' : y,
'class': 'noun-icon'
});
$viewport.append($svg);
$drawn.text('Drawn ' + i + ' of ' + numNouns);
i += 1;
if (i < numNouns) {
while ($.inArray(i, blacklist) > -1 && i < numNouns) {
i += 1;
}
setTimeout(function() { load(i); }, 10);
}
});
};
load(1);
$('#noun-container').svgPan('viewport');
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment