<?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/"
	>

<channel>
	<title>La fatiga del Geek &#187; Python</title>
	<atom:link href="http://nauj27.com/blog/category/programacion/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://nauj27.com/blog</link>
	<description>Reflexiones y cacharreos de nauj27</description>
	<lastBuildDate>Wed, 23 Jun 2010 17:14:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Usar Javascript desde Python</title>
		<link>http://nauj27.com/blog/2009/01/02/usar-javascript-desde-python/</link>
		<comments>http://nauj27.com/blog/2009/01/02/usar-javascript-desde-python/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 20:29:36 +0000</pubDate>
		<dc:creator>nauj27</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://nauj27.com/blog/?p=534</guid>
		<description><![CDATA[Desde la web de Caja GRANADA se pueden enviar 30 SMS al mes si se tiene acceso a la caja electrónica. Cuando estoy en casa y envío un SMS desde el iPhone usando la conexión wifi es realmente incómodo. La web de Caja GRANADA es&#8230; increíble. Y lo digo en el más irónico de los [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_536" class="wp-caption alignleft" style="width: 251px"><img class="size-full wp-image-536" title="python-logo" src="http://nauj27.com/blog/wp-content/uploads/2009/01/python-logo.png" alt="Python" width="241" height="101" /><p class="wp-caption-text">Python</p></div>
<p style="text-align: justify;">Desde la web de <a href="httphttp://caja.caja-granada.es/">Caja GRANADA</a> se pueden enviar 30 SMS al mes si se tiene acceso a la <a href="https://www.caja-granada.es/2031/01LOGIN1.htm">caja electrónica</a>.</p>
<p style="text-align: justify;">Cuando estoy en casa y envío un SMS desde el iPhone usando la conexión wifi es <em>realmente incómodo</em>. La web de Caja GRANADA es&#8230; increíble. Y lo digo en el más irónico de los sentidos, o no. Es frame sobre frame, tabla sobre tabla, una encrucijada de código que al iPhone se le atraganta un poco.</p>
<p style="text-align: justify;">Se puede llegar a usar pero para colmo tiene un contador de caracteres mientras se escribe el mensaje para el SMS que quita el foco al campo de entrada. Como consecuencia el teclado virtual se esconde con cada letra y no hay manera de escribir unas palabras sin desesperarse.</p>
<p style="text-align: justify;">Por otro lado hay algo en esta web que hacen bien en mi opinión, y es cuidar la seguridad. Sin entrar en detalles diré que la clave que escribes para entrar no es enviada, sino que se envía el resultado de un cifrado <a href="http://es.wikipedia.org/wiki/Triple_DES">triple des</a> de la misma. Hace unos meses usaban tan solo <a href="http://es.wikipedia.org/wiki/Data_Encryption_Standard">des</a> y gracias a una librería en python conseguí el mismo resultado. Esta vez no sé por qué por más parámetros que probé no conseguía el mismo resultado así que tenía básicamente dos opciones:</p>
<h2 style="text-align: justify;"><strong>Implementar el código javascript de caja granada en python</strong></h2>
<p style="text-align: justify;">Me daba mucha pereza y quise buscar algo más antes de ponerme manos a la obra.</p>
<h2 style="text-align: justify;">Ejecutar javascript desde python</h2>
<p>Aquí es donde entra en juego <a href="http://code.google.com/p/python-spidermonkey/">python-spidermonkey</a>. La instalación consiste en seguir los pasos indicados en la web para ello, bajando la versión de SVN. Su uso es muy sencillo de modo que esto es básicamente lo que hice:</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
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> spidermonkey <span style="color: #ff7700;font-weight:bold;">import</span> Runtime
<span style="color: #ff7700;font-weight:bold;">def</span> js_des<span style="color: black;">&#40;</span>clave, pin<span style="color: black;">&#41;</span>:
    runtime = Runtime<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    context = runtime.<span style="color: black;">new_context</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    context.<span style="color: black;">eval_script</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;var mod3 = function() {}&quot;</span><span style="color: black;">&#41;</span>
    context.<span style="color: black;">eval_script</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&quot;&quot;
        mod3.prototype.des = function(hexKey, message, encrypt, mode, iv, padding) {
            // código de la función pegado literalmente del js de cajagranada
            // ...
    &quot;&quot;&quot;</span><span style="color: black;">&#41;</span>
    context.<span style="color: black;">eval_script</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&quot;&quot;
        mod3.prototype.des_createKeys = function(key) {
            // blah blah blah...
    &quot;&quot;&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: #808080; font-style: italic;"># ...</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> context.<span style="color: black;">eval_script</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;m = new mod3(); m.des('%s', '%s');&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>clave, pin<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p style="text-align: justify;">Y finalmente para usarlo tan solo habrá que hacer algo similar a lo siguiente:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> md3
&nbsp;
<span style="color: #808080; font-style: italic;"># [...]</span>
pin_cifrado = mod3.<span style="color: black;">js_des</span><span style="color: black;">&#40;</span>clave, credenciales.<span style="color: black;">PIN</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Y de este modo la variable pin_cifrado tomará el valor devuelto por la función en javascript.</p>
]]></content:encoded>
			<wfw:commentRss>http://nauj27.com/blog/2009/01/02/usar-javascript-desde-python/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Migración a WordPress completada</title>
		<link>http://nauj27.com/blog/2008/06/15/migracion-a-wordpress-completada/</link>
		<comments>http://nauj27.com/blog/2008/06/15/migracion-a-wordpress-completada/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 19:36:54 +0000</pubDate>
		<dc:creator>nauj27</dc:creator>
				<category><![CDATA[Programación]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://nauj27.com/blog/?p=453</guid>
		<description><![CDATA[Bueno pues al fin he realizado la migración. Por el camino he perdido alguna información como las categorías, los usuarios registrados y el estilo visual de la web, pero en el fondo ha merecido la pena. Hace un par de años migré el blog antiguo a utf8, por lo que los caracteres acentuados se quedaron [...]]]></description>
			<content:encoded><![CDATA[<p>Bueno pues al fin he realizado <a title="Migración de pmachine a wordpress" href="http://nauj27.com/blog/2008/06/14/diez-motivos-por-los-que-migrar-a-wordpress/">la migración</a>. Por el camino he perdido alguna información como las categorías, los usuarios registrados y el estilo visual de la web, pero en el fondo ha merecido la pena. Hace un par de años migré el blog antiguo a <strong>utf8</strong>, por lo que los caracteres acentuados se quedaron un poco regular. Ahora se habían quedado peor aún así que me he hecho un pequeño programa para arreglarlo.</p>
<p>Después de tener la base de datos con todos los artículos y comentarios he realizado un volcado de la base de datos completa y he aplicado el siguiente script en python:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># -*- encoding: utf-8 -*-</span>
&nbsp;
inputFile = <span style="color: #483d8b;">'post_wordpressnauj27.sql'</span>
outputFile = <span style="color: #483d8b;">'post-out-wordpressnauj27.sql'</span>
&nbsp;
fin = <span style="color: #008000;">file</span><span style="color: black;">&#40;</span>inputFile, <span style="color: #483d8b;">'rt'</span><span style="color: black;">&#41;</span>
fout = <span style="color: #008000;">file</span><span style="color: black;">&#40;</span>outputFile, <span style="color: #483d8b;">'wt'</span><span style="color: black;">&#41;</span>
&nbsp;
finBuffer = fin.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
fin.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
foutBuffer = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
badChars =  <span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;Ã¡&quot;</span>, u<span style="color: #483d8b;">&quot;Ã©&quot;</span>, u<span style="color: #483d8b;">&quot;Ã­&quot;</span>, u<span style="color: #483d8b;">&quot;Ã³&quot;</span>, u<span style="color: #483d8b;">&quot;Ãº&quot;</span>, u<span style="color: #483d8b;">&quot;Â¿&quot;</span>, u<span style="color: #483d8b;">&quot;â‚¬&quot;</span>, u<span style="color: #483d8b;">&quot;Ã±&quot;</span>, u<span style="color: #483d8b;">&quot;Â¡&quot;</span>, u<span style="color: #483d8b;">&quot;Â¬&quot;</span><span style="color: black;">&#41;</span>
fixedChars = <span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;á&quot;</span>, u<span style="color: #483d8b;">&quot;é&quot;</span>, u<span style="color: #483d8b;">&quot;í&quot;</span>, u<span style="color: #483d8b;">&quot;ó&quot;</span>, u<span style="color: #483d8b;">&quot;ú&quot;</span>, u<span style="color: #483d8b;">&quot;¿&quot;</span>, u<span style="color: #483d8b;">&quot;€&quot;</span>, u<span style="color: #483d8b;">&quot;ñ&quot;</span>, u<span style="color: #483d8b;">&quot;¡&quot;</span>, u<span style="color: #483d8b;">&quot;¬&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> finBuffer:
    line = line.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'utf-8'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> index <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>badChars<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
        line = line.<span style="color: black;">replace</span><span style="color: black;">&#40;</span>badChars<span style="color: black;">&#91;</span>index<span style="color: black;">&#93;</span>, fixedChars<span style="color: black;">&#91;</span>index<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    foutBuffer.<span style="color: black;">append</span><span style="color: black;">&#40;</span>line.<span style="color: black;">encode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'utf-8'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
fout.<span style="color: black;">writelines</span><span style="color: black;">&#40;</span>foutBuffer<span style="color: black;">&#41;</span>
fout.<span style="color: black;">flush</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
fout.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Una vez hecho esto he volcado el resultado de nuevo en la base de datos y listo. Lo siguiente será personalizar el aspecto de la web y dejar de usar la plantilla por defecto.</p>
]]></content:encoded>
			<wfw:commentRss>http://nauj27.com/blog/2008/06/15/migracion-a-wordpress-completada/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
