|
@@ -229,47 +229,47 @@ |
|
|
<td class="linenos"> |
|
|
<td class="linenos"> |
|
|
<div class="linenodiv"> |
|
|
<div class="linenodiv"> |
|
|
<pre> 1 |
|
|
<pre> 1 |
|
|
2 |
|
|
|
|
|
3 |
|
|
|
|
|
4 |
|
|
|
|
|
5 |
|
|
|
|
|
6 |
|
|
|
|
|
7 |
|
|
|
|
|
8 |
|
|
|
|
|
9 |
|
|
|
|
|
10 |
|
|
|
|
|
11 |
|
|
|
|
|
12 |
|
|
|
|
|
13 |
|
|
|
|
|
14 |
|
|
|
|
|
15 |
|
|
|
|
|
16 |
|
|
|
|
|
17 |
|
|
|
|
|
18 |
|
|
|
|
|
19</pre> |
|
|
|
|
|
|
|
|
2 |
|
|
|
|
|
3 |
|
|
|
|
|
4 |
|
|
|
|
|
5 |
|
|
|
|
|
6 |
|
|
|
|
|
7 |
|
|
|
|
|
8 |
|
|
|
|
|
9 |
|
|
|
|
|
10 |
|
|
|
|
|
11 |
|
|
|
|
|
12 |
|
|
|
|
|
13 |
|
|
|
|
|
14 |
|
|
|
|
|
15 |
|
|
|
|
|
16 |
|
|
|
|
|
17 |
|
|
|
|
|
18 |
|
|
|
|
|
19</pre> |
|
|
</div> |
|
|
</div> |
|
|
</td> |
|
|
</td> |
|
|
<td class="code"> |
|
|
<td class="code"> |
|
|
<div class="highlight"> |
|
|
<div class="highlight"> |
|
|
<pre><span class="c">#!/usr/bin/env python</span> |
|
|
<pre><span class="c">#!/usr/bin/env python</span> |
|
|
|
|
|
|
|
|
<span class="kn">from</span> <span class="nn">json</span> <span class="kn">import</span> <span class="n">loads</span> |
|
|
|
|
|
<span class="kn">from</span> <span class="nn">sys</span> <span class="kn">import</span> <span class="n">argv</span> |
|
|
|
|
|
<span class="kn">from</span> <span class="nn">urllib</span> <span class="kn">import</span> <span class="n">urlencode</span> |
|
|
|
|
|
<span class="kn">from</span> <span class="nn">urllib2</span> <span class="kn">import</span> <span class="n">urlopen</span> |
|
|
|
|
|
|
|
|
<span class="kn">from</span> <span class="nn">json</span> <span class="kn">import</span> <span class="n">loads</span> |
|
|
|
|
|
<span class="kn">from</span> <span class="nn">sys</span> <span class="kn">import</span> <span class="n">argv</span> |
|
|
|
|
|
<span class="kn">from</span> <span class="nn">urllib</span> <span class="kn">import</span> <span class="n">urlencode</span> |
|
|
|
|
|
<span class="kn">from</span> <span class="nn">urllib2</span> <span class="kn">import</span> <span class="n">urlopen</span> |
|
|
|
|
|
|
|
|
<span class="k">def</span> <span class="nf">get_function</span><span class="p">(</span><span class="n">name</span><span class="p">):</span> |
|
|
|
|
|
<span class="n">params</span> <span class="o">=</span> <span class="p">{</span><span class="s">"q"</span><span class="p">:</span> <span class="s">"lang:python and func:def:</span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="n">name</span><span class="p">}</span> |
|
|
|
|
|
<span class="n">request</span> <span class="o">=</span> <span class="n">urlopen</span><span class="p">(</span><span class="s">"http://bitshift.it/search.json?"</span> <span class="o">+</span> <span class="n">urlencode</span><span class="p">(</span><span class="n">params</span><span class="p">))</span> |
|
|
|
|
|
<span class="n">res</span> <span class="o">=</span> <span class="n">loads</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">read</span><span class="p">())[</span><span class="s">"results"</span><span class="p">]</span> |
|
|
|
|
|
<span class="k">if</span> <span class="n">res</span><span class="p">:</span> |
|
|
|
|
|
<span class="k">print</span> <span class="s">"</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">res</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s">"url"</span><span class="p">])</span> |
|
|
|
|
|
<span class="k">else</span><span class="p">:</span> |
|
|
|
|
|
<span class="k">print</span> <span class="s">"</span><span class="si">%s</span><span class="s"> not found."</span> <span class="o">%</span> <span class="n">name</span> |
|
|
|
|
|
|
|
|
<span class="k">def</span> <span class="nf">get_function</span><span class="p">(</span><span class="n">name</span><span class="p">):</span> |
|
|
|
|
|
<span class="n">params</span> <span class="o">=</span> <span class="p">{</span><span class="s">"q"</span><span class="p">:</span> <span class="s">"lang:python and func:def:</span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="n">name</span><span class="p">}</span> |
|
|
|
|
|
<span class="n">request</span> <span class="o">=</span> <span class="n">urlopen</span><span class="p">(</span><span class="s">"http://bitshift.it/search.json?"</span> <span class="o">+</span> <span class="n">urlencode</span><span class="p">(</span><span class="n">params</span><span class="p">))</span> |
|
|
|
|
|
<span class="n">res</span> <span class="o">=</span> <span class="n">loads</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">read</span><span class="p">())[</span><span class="s">"results"</span><span class="p">]</span> |
|
|
|
|
|
<span class="k">if</span> <span class="n">res</span><span class="p">:</span> |
|
|
|
|
|
<span class="k">print</span> <span class="s">"</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">res</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s">"url"</span><span class="p">])</span> |
|
|
|
|
|
<span class="k">else</span><span class="p">:</span> |
|
|
|
|
|
<span class="k">print</span> <span class="s">"</span><span class="si">%s</span><span class="s"> not found."</span> <span class="o">%</span> <span class="n">name</span> |
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">"__main__"</span><span class="p">:</span> |
|
|
|
|
|
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">argv</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span> |
|
|
|
|
|
<span class="n">get_function</span><span class="p">(</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> |
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">"__main__"</span><span class="p">:</span> |
|
|
|
|
|
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">argv</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span> |
|
|
|
|
|
<span class="n">get_function</span><span class="p">(</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> |
|
|
</pre> |
|
|
</pre> |
|
|
</div> |
|
|
</div> |
|
|
</td> |
|
|
</td> |
|
|