<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>Mahadeva &#187; simplejson</title>
	<atom:link href="http://www.patriciomolina.com/tag/simplejson/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.patriciomolina.com</link>
	<description>Blog de Patricio Molina</description>
	<lastBuildDate>Mon, 06 Feb 2012 04:26:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-sa/2.5/ar/</creativeCommons:license>		<item>
		<title>Consultando Crunchbase con Python</title>
		<link>http://www.patriciomolina.com/2009/09/consultando-crunchbase-con-python/</link>
		<comments>http://www.patriciomolina.com/2009/09/consultando-crunchbase-con-python/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 21:52:33 +0000</pubDate>
		<dc:creator>Pato</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[crunchbase]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[simplejson]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.patriciomolina.com/?p=91</guid>
		<description><![CDATA[Por mi trabajo, siempre estoy pendiente de lo que sucede en Crunchbase (de hecho, estoy suscripto a su feed de páginas recientes). Con tantas empresas y personas yendo y viniendo por Twitter, se transformó en una fuente de consulta permanente. &#8230; <a href="http://www.patriciomolina.com/2009/09/consultando-crunchbase-con-python/">Sigue leyendo <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Por mi trabajo, siempre estoy pendiente de lo que sucede en <a href="http://www.crunchbase.com/">Crunchbase</a> (de hecho, estoy suscripto a su <em><a href="http://es.wikipedia.org/wiki/Fuente_web">feed</a></em> de <a href="http://crunchbase.com/recently-added.rss">páginas recientes</a>). Con tantas empresas y personas yendo y viniendo por Twitter, se transformó en una fuente de consulta permanente.</p>
<p>¿Puedo consultar Crunchbase con Python? La respuesta es obvia <img src='http://www.patriciomolina.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Crunchbase tiene una <a href="http://es.wikipedia.org/wiki/Interfaz_de_programaci%C3%B3n_de_aplicaciones">API</a> muy interesante que devuelve resultados en formato <a href="http://es.wikipedia.org/wiki/JSON">JSON</a>. Pueden encontrar documentación sobre su uso en <a href="http://groups.google.com/group/crunchbase-api/">crunchbase-api</a>.</p>
<p>Para este programa estoy usando la librería <a href="http://pypi.python.org/pypi/simplejson/">simplejson</a> (<tt>sudo apt-get install python-simplejson</tt>)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>, <span style="color: #dc143c;">urllib</span>, simplejson
&nbsp;
api = <span style="color: #483d8b;">'http://api.crunchbase.com/v/1/search.js?%s'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff4500;">2</span>:
        q = <span style="color: #483d8b;">' '</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        source = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>api <span style="color: #66cc66;">%</span> <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlencode</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'query'</span>: q<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        results = simplejson.<span style="color: black;">loads</span><span style="color: black;">&#40;</span>source.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> results<span style="color: black;">&#91;</span><span style="color: #483d8b;">'results'</span><span style="color: black;">&#93;</span>:
            <span style="color: #ff7700;font-weight:bold;">for</span> r <span style="color: #ff7700;font-weight:bold;">in</span> results<span style="color: black;">&#91;</span><span style="color: #483d8b;">'results'</span><span style="color: black;">&#93;</span>:
                name = r.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'name'</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> name:
                    name = <span style="color: #483d8b;">' '</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>w.<span style="color: black;">capitalize</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> \
                        <span style="color: #ff7700;font-weight:bold;">for</span> w <span style="color: #ff7700;font-weight:bold;">in</span> r<span style="color: black;">&#91;</span><span style="color: #483d8b;">'permalink'</span><span style="color: black;">&#93;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-'</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'%s (%s): %s'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>
                    name.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,
                    r<span style="color: black;">&#91;</span><span style="color: #483d8b;">'namespace'</span><span style="color: black;">&#93;</span>.<span style="color: black;">capitalize</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,
                    r<span style="color: black;">&#91;</span><span style="color: #483d8b;">'crunchbase_url'</span><span style="color: black;">&#93;</span>,
                <span style="color: black;">&#41;</span>       
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'No results for &quot;%s&quot;'</span> <span style="color: #66cc66;">%</span> q
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Usage: python %s &lt;keyword(s)&gt;'</span> <span style="color: #66cc66;">%</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Aquí tienen algunos resultados:</p>
<pre>mahadeva@blue:~$ python crunchbase.py
Usage: python crunchbase.py
mahadeva@blue:~$ python crunchbase.py popego
Popego (Company): http://www.crunchbase.com/company/popego
Santiago Siri (Person): http://www.crunchbase.com/person/santiago-siri
</pre>
<p>El programa en sí no es muy cómodo de usar (para eso existen los <em>add-ons</em> de de Firefox <img src='http://www.patriciomolina.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ), pero es un buen punto de partida para utilizar, por ejemplo, como una <a href="http://www.djangoproject.com/">aplicación de Django</a>, o un <em>bot</em> que interactúe con <a href="http://www.twitter.com/">Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patriciomolina.com/2009/09/consultando-crunchbase-con-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

