<?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>sector-5.net &#187; Python</title>
	<atom:link href="http://sector-5.net/archives/category/programming/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://sector-5.net</link>
	<description></description>
	<lastBuildDate>Wed, 06 Apr 2011 08:40:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>irssi-python for irssi 0.8.15</title>
		<link>http://sector-5.net/archives/irssi-python-for-irssi-0-8-15/</link>
		<comments>http://sector-5.net/archives/irssi-python-for-irssi-0-8-15/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 21:45:49 +0000</pubDate>
		<dc:creator>Anonymous</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://sector-5.net/?p=111</guid>
		<description><![CDATA[I recently became aware of a Python plugin for irssi, which conveniently resides in the irssi SVN repository. This plugin presumably exposes an API very similar to the one used in the Perl plugin, so creating new scripts should be easy with all those Perl samples out there. 

There&#8217;s an useful guide for building the [...]]]></description>
			<content:encoded><![CDATA[<p>I recently became aware of a Python plugin for irssi, which conveniently resides in the <a href="http://svn.irssi.org/repos/irssi-python">irssi SVN repository</a>. This plugin presumably exposes an API very similar to the one used in the Perl plugin, so creating new scripts should be easy with all those Perl samples out there. </p>

<p>There&#8217;s an useful guide for <a href="http://bsg.lericson.se/howto-irssi-python.html">building the plugin here</a>, but I found that some lose ends still needed to be patched up. </p>

<p>For one, the plugin apparently hasn&#8217;t been updated in a while, so some function calls still reference old irssi structures and functions. Naturally, these don&#8217;t compile with irssi 0.8.15, which is the latest version as of this writing. For those issues, I compiled <a href="http://files.sector-5.net/irssi-python-for-0.8.14.patch">a patch with various fixes here</a>. This isn&#8217;t exactly a perfect fix, but should do in most cases. (The name is still 0.8.14 as that is the version it was originally written for, but it still applies cleanly for 0.8.15)</p>

<p><code>ac_python_devel.m4</code> can be downloaded from various sources, for example from <a href="http://stasis.googlecode.com/svn/trunk/m4/ac_python_devel.m4">this project</a>. <code>pyconstants.c</code> is supposed to be generated with <code>awk -f src/constants.awk src/constants.txt &gt; src/pyconstants.c</code>.</p>

<p>There is one more catch that isn&#8217;t mentioned in above guide: The plugin tries to load <code>irssi_startup.py</code> on startup, which will have to be on a specific path to be found. Without any parameters to <code>./configure</code>, that will be <code>/usr/local/share/irssi/scripts</code>. So, if you&#8217;d rather have it in <code>/usr/share/irssi/scripts</code> (this is where my distribution places scripts, at least), you have to explicitly specify this when calling <code>./configure</code>:</p>

<pre><code>./configure --with-irssi=&lt;path to irssi sources&gt; \
    --datadir=/usr/share
</code></pre>

<p>After that, make should (<em>hopefully</em>) work and <code>libpython.so</code> will be placed in <code>src/.libs/</code>. This file should be moved to irssi&#8217;s module directory, which should be <code>/usr/lib/irssi/modules</code> or <code>/usr/local/lib/irssi/modules</code>, depending on distribution.
Copy <code>irssi_startup.py</code> and <code>irssi.py</code> from <code>src/</code> to the data directory you specified above, and irssi should be able to load the Python plugin without problems via <code>/load python</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sector-5.net/archives/irssi-python-for-irssi-0-8-15/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>X-Chat plugin: AniDB Search</title>
		<link>http://sector-5.net/archives/x-chat-plugin-anidb-search/</link>
		<comments>http://sector-5.net/archives/x-chat-plugin-anidb-search/#comments</comments>
		<pubDate>Fri, 23 Mar 2007 08:19:58 +0000</pubDate>
		<dc:creator>Anonymous</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[X-Chat]]></category>

		<guid isPermaLink="false">http://sector-5.net/archives/x-chat-plugin-anidb-search/</guid>
		<description><![CDATA[More useless plugins for X-Chat: AniDBSearch, triggered by channel text starting with .anidb, looks up the search string on AniDB and prints the corresponding AniDB entry url, or the search url if multiple results matching the search string were found. Nothing too fancy. Can also be triggered by typing /anidb.

PS: No AniDB API calls. Just [...]]]></description>
			<content:encoded><![CDATA[<p>More useless plugins for X-Chat: AniDBSearch, triggered by channel text starting with .anidb, looks up the search string on AniDB and prints the corresponding AniDB entry url, or the search url if multiple results matching the search string were found. Nothing too fancy. Can also be triggered by typing /anidb.</p>

<p>PS: No AniDB API calls. Just HTTP fetch and some regexps.</p>

<p>Current: <a href="http://files.sector-5.net/anidbsearch-2.2.py" title="AniDBSearch 2.2">AniDBSearch 2.2</a></p>

<p><span id="more-34"></span></p>

<p>Changelog:</p>

<ul>
<li>2.2

<ul>
<li>Updated AniDB regexps.</li>
<li>Added official Japanese title to output. Be sure to set server encoding to UTF-8, this isn&#8217;t 1990 anymore!</li>
<li>When more than one anime matches the search string, AniDBSearch now prints the first few results instead of just the actual search URL. </li>
<li>Added message throttling to avoid being flooded off during above operation.</li>
<li>No longer uses threaded HTTP fetch on win32. This means that the client will become unresponsive for a while after each command. It also means that the script might now actually work on win32. After some poking around I&#8217;m no longer sure it ever did. If anyone manages to fit threads and the X-Chat Python plugin &#8211; especially xchat.command &#8211;  together, be sure to let me know.</li>
<li>Various other, minor cleanups.</li>
</ul></li>
<li>2.1.4

<ul>
<li>Fixed wrong results when disabling command or trigger (disabling the trigger actually disabled the command and vice versa)</li>
<li>Fixed printing in the wrong context (Thanks to protospork for pointing it out, I never noticed)</li>
</ul></li>
<li>2.1.3

<ul>
<li>Fixed crash due to invalid arguments to /anidb</li>
<li>Fixed exception in connection handler</li>
</ul></li>
<li>2.1.2

<ul>
<li>Updated AniDB URL and regexps</li>
</ul></li>
<li>2.1.1:

<ul>
<li>Added /anidb -b to open AniDB URL in browser</li>
<li>Added /anidb -p to output the URL to the current channel instead of privmsg.<br />
This can be considered a workaround to using .anidb yourself (see below)</li>
<li>Disabled &#8220;Your Message&#8221; hook on win32 &#8211; locks up X-Chat</li>
<li>Fixes for backward compatibility to Python 2.4</li>
</ul></li>
<li>2.1.0:

<ul>
<li>Completely rewritten previous code</li>
</ul></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://sector-5.net/archives/x-chat-plugin-anidb-search/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MPCinfo X-Chat plugin, Take 2</title>
		<link>http://sector-5.net/archives/mpcinfo-x-chat-plugin-take-2/</link>
		<comments>http://sector-5.net/archives/mpcinfo-x-chat-plugin-take-2/#comments</comments>
		<pubDate>Wed, 20 Dec 2006 10:04:03 +0000</pubDate>
		<dc:creator>Anonymous</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[X-Chat]]></category>

		<guid isPermaLink="false">http://sector-5.net/archives/mpcinfo-x-chat-plugin-take-2/</guid>
		<description><![CDATA[Wasn&#8217;t really that happy with the earlier version of the plugin, so I modified the mpcinfo-Sources to compile as a native Python plugin, thus eliminating the need for a DLL wrapper. This marks the my first time with the Python/C-API. Quite convenient.

The new version can be downloaded here:
MPCinfo 1.3.1

There used to be C++ sources for [...]]]></description>
			<content:encoded><![CDATA[<p>Wasn&#8217;t really that happy with the earlier version of the plugin, so I modified the mpcinfo-Sources to compile as a native Python plugin, thus eliminating the need for a DLL wrapper. This marks the my first time with the Python/C-API. Quite convenient.</p>

<p>The new version can be downloaded here:
<a href="http://files.sector-5.net/mpcinfo-1.3.1.rar" title="MPCinfo 1.3.1">MPCinfo 1.3.1</a></p>

<p>There used to be C++ sources for the .pyd file and some instructions included in the archive, but I unfortunately lost the source and the original archive, so you&#8217;ll have to make do with just the essentials. <img src='http://sector-5.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://sector-5.net/archives/mpcinfo-x-chat-plugin-take-2/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>MPC Status plugin for X-Chat 2</title>
		<link>http://sector-5.net/archives/mpc-status-plugin-for-x-chat-2/</link>
		<comments>http://sector-5.net/archives/mpc-status-plugin-for-x-chat-2/#comments</comments>
		<pubDate>Mon, 18 Dec 2006 22:16:42 +0000</pubDate>
		<dc:creator>Anonymous</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[X-Chat]]></category>

		<guid isPermaLink="false">http://sector-5.net/archives/mpc-status-plugin-for-x-chat-2/</guid>
		<description><![CDATA[It seems I finally got my MPCInfo plugin for X-Chat working, as far as not crashing X-Chat after a set amount of time is concerned. The point is, basically, to output the file currently playing in Media Player Classic to the current channel, similar to mIRC plugins such as GTSDll, but without all the bloat [...]]]></description>
			<content:encoded><![CDATA[<p>It seems I finally got my MPCInfo plugin for X-Chat working, as far as not crashing X-Chat after a set amount of time is concerned. The point is, basically, to output the file currently playing in <a href="http://sourceforge.net/project/showfiles.php?group_id=82303&amp;package_id=84358" title="Media Player Classic by Gabest">Media Player Classic</a> to the current channel, similar to mIRC plugins such as <a href="http://www.gts-stuff.com/" title="GTSDll plugin for mIRC">GTSDll</a>, but without all the bloat I&#8217;m not using anyway. The output currently looks like the following example, but should be fairly easy to change if you know what you&#8217;re doing.</p>

<blockquote>[ TwoPoints] <b>MPC</b>: [Eclipse] Itadaki no Hecatetan &#8211; 01 (h264) [81CA68B4].mkv : [00:00/08:04 min (stopped)] : Size: 64.59 mb</blockquote>

<p><span id="more-28"></span></p>

<p>The script itself is using <a href="http://guliverkli.svn.sourceforge.net/viewvc/guliverkli/trunk/guliverkli/src/apps/mpcinfo/" title="mpcinfo.dll Source code">mpcinfo.dll</a> by Gabest and requires Python 2.5 (I believe X-Chat versions >= 2.6.8 are linked against 2.5, so you should be all set if you use a moderately recent version). Since mpcinfo.dll was intended for mIRC use, the exported functions are defined according to mIRC DLL standards, so most of the work in this plugin actually was to wrap the functions to somwhat use them in Python. Maybe I&#8217;ll try and recompile the DLL to a native X-Chat plugin one day, who knows.</p>

<p>Unfortunately I can no longer provide the old version since my provider lost it due to a hardware crash and I do not have the files anymore.</p>
]]></content:encoded>
			<wfw:commentRss>http://sector-5.net/archives/mpc-status-plugin-for-x-chat-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache and mod_python on Windows</title>
		<link>http://sector-5.net/archives/apache-and-mod_python-on-windows/</link>
		<comments>http://sector-5.net/archives/apache-and-mod_python-on-windows/#comments</comments>
		<pubDate>Wed, 29 Nov 2006 09:16:00 +0000</pubDate>
		<dc:creator>Anonymous</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://sector-5.net/archives/apache-and-mod_python-on-windows/</guid>
		<description><![CDATA[Just a friendly reminder for myself how to get Apache 2.2 and mod_python 3.3.x working again after I wasted almost five hours trying to get it running again after upgrading from an older version and Apache 2.0.54.


Prerequisites: Install Apache and Python


Accquire and compile SVN snapshot of mod_python
Install resulting Python package
LoadModule python&#95;module modules/mod&#95;python.so in httpd.conf


I was [...]]]></description>
			<content:encoded><![CDATA[<p>Just a friendly reminder for myself how to get Apache 2.2 and mod_python 3.3.x working again after I wasted almost five hours trying to get it running again after upgrading from an older version and Apache 2.0.54.</p>

<p><span id="more-26"></span>
Prerequisites: Install Apache and Python</p>

<ul>
<li>Accquire and compile SVN snapshot of mod_python</li>
<li>Install resulting Python package</li>
<li>LoadModule python&#95;module modules/mod&#95;python.so in httpd.conf</li>
</ul>

<p>I was stuck for hours because of this simple problem: mod&#95;python.so is dependant on python24.dll (or any other version, depending on what version of Python mod&#95;python was linked against during compile time), and Apache will report &#8220;Cannot find module&#8221; instead of &#8220;Cannot load dependency&#8221; or something if this DLL cannot be found.<br />
This is where adding PathToPython to the global PATH enviroment variable comes into play. If you add it to the local PATH variable instead of the global one, you&#8217;ll need to start the Apache service under your Windows account name. (Duh, if I was into masochism I&#8217;d bump my head against a wall endlessly for wasting my time like this)</p>
]]></content:encoded>
			<wfw:commentRss>http://sector-5.net/archives/apache-and-mod_python-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ye&#8217; ol&#8217; Django Templating System</title>
		<link>http://sector-5.net/archives/ye-ol-django-templating-system/</link>
		<comments>http://sector-5.net/archives/ye-ol-django-templating-system/#comments</comments>
		<pubDate>Thu, 27 Jul 2006 20:56:12 +0000</pubDate>
		<dc:creator>Anonymous</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://sector-5.net/archives/ye-ol-django-templating-system/</guid>
		<description><![CDATA[The past days I&#8217;ve been playing Fire Emblem for  Game Boy Advanced again. Highly entertaining and addicting, on a sidenote. Anyway, I was missing some kind of reference on who has support relations to whom, who promotes into what and these kind of things. So, without further ado, I tried writing one myself, using [...]]]></description>
			<content:encoded><![CDATA[<p>The past days I&#8217;ve been playing Fire Emblem for  Game Boy Advanced again. Highly entertaining and addicting, on a sidenote. Anyway, I was missing some kind of reference on who has support relations to whom, who promotes into what and these kind of things. So, without further ado, I tried writing one myself, using the now quite popular <a href="http://www.djangoproject.net">Django Web Framework</a> for Python. After a short learning period things went quite smoothly &#8211; until I tried to a bit more complex things in the templating engine, that is.</p>

<p><span id="more-24"></span>
Image this: You have a list of objects, and each of this objects needs another list with attributes &#8211; but you can&#8217;t store the list on the object, because it is read-only (I&#8217;m talking about a database object here). So, you think: Just add another dictionary to the namespace, with the object as key and the list as value. Except &#8211; in no way you can access dictionary keys in the template.</p>

<ul>
<li><em>dict.key</em> &#8211; No</li>
<li><em>dict[key]</em> &#8211; No</li>
<li><em>dict.{{key}}</em> &#8211; (Yeah, I even got that desperate) &#8211; No</li>
</ul>

<p>No function calls with arguments other than string either. A somewhat restrictive system, in my humble opinion. I&#8217;m not an idiot, and want to decide when and where to call functions myself, thank you. Until these issues are resolved or can at least be worked around without a crazy amount of ugly hacks I&#8217;ll rather be using <a href="http://www.cheetahtemplate.org">Cheetah</a> for my templates. It fuses into Django quite well, so I was able to rewrite my templates in a minimal amount of time. (Granted, I was using Cheetah for another project before and thous was familiar with the syntax already).</p>
]]></content:encoded>
			<wfw:commentRss>http://sector-5.net/archives/ye-ol-django-templating-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python wallpaper changer</title>
		<link>http://sector-5.net/archives/python-wallpaper-changer/</link>
		<comments>http://sector-5.net/archives/python-wallpaper-changer/#comments</comments>
		<pubDate>Thu, 09 Jun 2005 11:30:53 +0000</pubDate>
		<dc:creator>Anonymous</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.sector-5.net/?p=11</guid>
		<description><![CDATA[With all those cool images I have sitting around on my computer it is often difficult to decide which to choose for my desktop. After a while I wondered if it would be possible to have Python select a random image from my wallpaper folder and set it as background. I digged around a bit [...]]]></description>
			<content:encoded><![CDATA[<p>With all those cool images I have sitting around on my computer it is often difficult to decide which to choose for my desktop. After a while I wondered if it would be possible to have Python select a random image from my wallpaper folder and set it as background. I digged around a bit and found a function <em>SystemParametersInfo</em> in user32.dll.  After some hassles with the parameters I finally managed to create this piece of code to change wallpaper on the fly.
Required modules are <a href="http://starship.python.net/crew/mhammond/win32/">win32all</a> and <a href="http://starship.python.net/crew/theller/ctypes/">ctypes</a> (for dll loading functions) as well as <a href="http://www.pythonware.com/products/pil/">Python Imaging Library</a> (to convert images to .BMP).  </p>

<p><span id="more-11"></span></p>

<p><strong>Code:</strong>
<pre>
<code>
import Image
from win32con import SPI_SETDESKWALLPAPER, SPIF_SENDCHANGE, SPIF_UPDATEINIFILE
from ctypes import windll, WinError

def set_wallpaper(filename):

    try:
        # Convert image to .bmp
        img = Image.open(filename)
        destination = r'C:\Windows\Wallpaper.bmp'
        img.save(destination)

        # Update wallpaper with SystemParametersInfo
        SPIF_TELLALL = SPIF_SENDCHANGE | SPIF_UPDATEINIFILE
        if not windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0,
                                                   destination, SPIF_TELLALL):
            raise WinError(descr = 'Error while setting wallpaper %s' % filename)
   
     except IOError, ioe:
        # Intercept errors when image could not be converted to .bmp, e.g. when the file is truncated or corrupt
        pass
</code>
</pre>
</p>
]]></content:encoded>
			<wfw:commentRss>http://sector-5.net/archives/python-wallpaper-changer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

