<?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:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>Yabfog &#187; python</title>
	<atom:link href="http://yabfog.com/blog/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://yabfog.com/blog</link>
	<description>Yet another blog full of gas</description>
	<lastBuildDate>Thu, 29 Jul 2010 20:33:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<cloud domain='yabfog.com' port='80' path='/blog/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>XMPP vCard Python Script</title>
		<link>http://yabfog.com/blog/2009/06/03/xmpp-vcard-python-script</link>
		<comments>http://yabfog.com/blog/2009/06/03/xmpp-vcard-python-script#comments</comments>
		<pubDate>Wed, 03 Jun 2009 16:39:31 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[gtalk]]></category>
		<category><![CDATA[jabber]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[vcard]]></category>
		<category><![CDATA[xmpp]]></category>

		<guid isPermaLink="false">http://yabfog.com/blog/?p=231</guid>
		<description><![CDATA[Couldn't find a script to update my Jabber/XMPP vCard photo (a/k/a avatar), so I wrote one. It requires xmpppy (a/k/a python-xmpp). It should work with gTalk, but I have not tested it. Credit to pastebin for some code snippets. Hope this saves someone some time and effort. #!/usr/bin/python '''vcard.py - Update your XMPP vcard photo [...]]]></description>
			<content:encoded><![CDATA[<p>Couldn't find a script to update my Jabber/XMPP vCard photo (a/k/a avatar), so I wrote one. It requires xmpppy (a/k/a python-xmpp). It should work with gTalk, but I have not tested it.</p>
<p>Credit to <a href="http://en.pastebin.ca/1237241">pastebin</a> for some code snippets.</p>
<p>Hope this saves someone some time and effort.</p>
<pre>
#!/usr/bin/python
'''vcard.py - Update your XMPP vcard photo with the image you provide

Usage: vcard.py image_file jid password
'''

from xmpp import JID, Client, Iq, Presence, NS_VERSION, NS_VCARD
import sys
import os
import time
from base64 import encode, decode
from hashlib import sha1

try:
    file=os.path.expanduser(sys.argv[1])
    jid=sys.argv[2]
    password=sys.argv[3]
    resource='vcard'
except:
    print >>sys.stderr, __doc__
    sys.exit(2)

NS_VCARD_UPDATE = 'vcard-temp:x:update'
NS_NICK = 'http://jabber.org/protocol/nick'

def hash_img(img):
    return sha1(img).hexdigest()

def base64_img(img):
    return img.encode('base64')

def get_img(file):
    try:
        os.stat(file)[6]
        fh = open(file, 'rb')
        img = fh.read()
        return img
    except Exception, e:
        print >>sys.stderr, e
        sys.exit(2)

def get_mime_type(file):
    try:
        ext = file[-4:]
        if ext == '.png':
            mime_type = 'image/png'
        elif ext == '.gif':
            mime_type = 'image/gif'
        elif ext == '.jpg' or ext == '.jpeg':
            mime_type = 'image/jpeg'
        else:
            raise ValueError, "Wrong mime-type detected. Check file suffix."
    except ValueError, e:
        print >>sys.stderr, e
        sys.exit(2)
    return mime_type

def send_vcard(conn, base64_img, mime_type, nick):
    iq_vcard = Iq(typ='set')
    vcard = iq_vcard.addChild(name='vCard', namespace=NS_VCARD)
    vcard.addChild(name='NICKNAME', payload=[nick])
    photo = vcard.addChild(name='PHOTO')
    photo.setTagData(tag='TYPE', val=mime_type)
    photo.setTagData(tag='BINVAL', val=base64_img)
    conn.send(iq_vcard)

def send_presence(conn, status, hash1, nick):
    presence = Presence(status = status, show = 'xa', priority = '-1')
    presence.setTag(name='x',namespace=NS_VCARD_UPDATE).setTag(name='photo',namespace=NS_VCARD_UPDATE).setData(hash1)
    presence.setTag(name='nick',namespace=NS_NICK).setData(nick)
    conn.send(presence)

if __name__ == '__main__':
    img = get_img(file)
    j=JID(jid)
    cl=Client(j.getDomain(),debug=[])
    conn=cl.connect()
    if not conn:
        raise Exception, 'failed to start connection'
    auth=cl.auth(j.getNode(),password,resource,sasl=1)
    if not auth:
        raise Exception, 'could not authenticate'
    send_vcard(cl, base64_img(img), get_mime_type(file), j.getNode())
    send_presence(cl, 'Updated vCard Image', hash_img(img), j.getNode())
    time.sleep(1)
    cl.disconnect()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://yabfog.com/blog/2009/06/03/xmpp-vcard-python-script/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
	</item>
		<item>
		<title>Itch Scratched</title>
		<link>http://yabfog.com/blog/2008/12/30/itch-scratched</link>
		<comments>http://yabfog.com/blog/2008/12/30/itch-scratched#comments</comments>
		<pubDate>Wed, 31 Dec 2008 00:07:42 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[nntp]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[xmpp]]></category>

		<guid isPermaLink="false">http://danmactough.posterous.com/itch-scratched</guid>
		<description><![CDATA[Ah... feels so good to scratch that itch. Python, nntp, twitter, xmpp.]]></description>
			<content:encoded><![CDATA[<p>Ah... feels so good to scratch that itch. Python, nntp, twitter, xmpp.
</p>
<p><a href='http://posterous.com/getfile/files.posterous.com/danmactough/lrFBEgjXDePtLegLowkFUBJAeKDJE2OIL7lPinZtiFHnBltlufU43dUq2j9B/subping01.png'><img src="http://posterous.com/getfile/files.posterous.com/danmactough/fvi9QoHrLn1hHOCHLyxzJx3ydaFa0uEkWquKbVNjyY56djvdE3ntgUVvCeyO/subping01.png.scaled.500.jpg" width="500" height="315"/></a></p>
]]></content:encoded>
			<wfw:commentRss>http://yabfog.com/blog/2008/12/30/itch-scratched/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://posterous.com/getfile/files.posterous.com/danmactough/fvi9QoHrLn1hHOCHLyxzJx3ydaFa0uEkWquKbVNjyY56djvdE3ntgUVvCeyO/subping01.png.scaled.500.jpg" />
		<media:content url="http://posterous.com/getfile/files.posterous.com/danmactough/fvi9QoHrLn1hHOCHLyxzJx3ydaFa0uEkWquKbVNjyY56djvdE3ntgUVvCeyO/subping01.png.scaled.500.jpg" medium="image" />
	</item>
		<item>
		<title>Jaiku Planet Venus Filter</title>
		<link>http://yabfog.com/blog/2008/03/12/jaiku-planet-venus-filter</link>
		<comments>http://yabfog.com/blog/2008/03/12/jaiku-planet-venus-filter#comments</comments>
		<pubDate>Thu, 13 Mar 2008 03:27:36 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[jaiku]]></category>
		<category><![CDATA[planet]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[venus]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://yabfog.com/wp/2008/03/12/jaiku-planet-venus-filter</guid>
		<description><![CDATA[Just started exploring Jaiku and, coincidentally, Planet Venus. One of the cool things about Jaiku is that it aggregates your other web presences (like your blog, twitter, del.icio.us, and flickr posts) and integrates them into Jaiku presence stream. The down side of this is that it's not as good at that as Planet Venus, and [...]]]></description>
			<content:encoded><![CDATA[<p>Just started exploring <a href="http://danmactough.jaiku.com/">Jaiku</a> and, coincidentally, <a href="http://www.intertwingly.net/code/venus/">Planet Venus</a>. One of the cool things about Jaiku is that it aggregates your other web presences (like your blog, twitter, del.icio.us, and flickr posts) and integrates them into Jaiku presence stream. The down side of this is that it's not as good at that as Planet Venus, and then if you use Planet Venus to create a aggregation of your web presences and you include Jaiku, then you've got annoying duplication.</p>
<p>So, I'm not much of a Python programmer, but I wrote this <a href="http://yabfog.com/files/fix_jaikus.py">Planet Venus filter</a> that looks at each entry, and if it detects that it's a Jaiku presence update, it only includes it if it originated via Jaiku. In other words, it filters out all the duplicates.</p>
<p>If you understood any of that, you may find this helpful. If not, nevermind.</p>
<p><code><br />
"""<br />
For jaiku presence entries, only retain entries that originate from jaiku<br />
(as opposed to grabbed via web feeds)<br />
"""<br />
import sys, xml.dom.minidom<br />
entry = xml.dom.minidom.parse(sys.stdin).documentElement<br />
entry_id = entry.getElementsByTagName('id')[0].firstChild.data<br />
for node in entry.getElementsByTagName('link'):<br />
  if node.getAttribute('rel') == 'alternate':<br />
    entry_link = node.getAttribute('href')<br />
    break<br />
if entry_id.find('jaiku.com/presence') &gt; 0 and (entry_id != entry_link):<br />
  sys.exit(1)<br />
print entry.toxml('utf-8')<br />
</code></p>
<p><em>(Updated to fix a bug on line 11.)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://yabfog.com/blog/2008/03/12/jaiku-planet-venus-filter/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
	</item>
		<item>
		<title>Juice-y Python</title>
		<link>http://yabfog.com/blog/2007/06/21/juice-y-python</link>
		<comments>http://yabfog.com/blog/2007/06/21/juice-y-python#comments</comments>
		<pubDate>Fri, 22 Jun 2007 02:09:11 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://yabfog.com/blog/2007/06/21/juice-y-python/</guid>
		<description><![CDATA[I use Juice to manage my podcasts. But it doesn't do everything I need, and it's a little buggy, and I want to learn Python anyway. So I decided to download the latest source code and see if I could fix some of the bugs I've noticed and figure out how to extend it to [...]]]></description>
			<content:encoded><![CDATA[<p>I use <a href="http://juicereceiver.sourceforge.net/">Juice</a> to manage my podcasts. But it doesn't do everything I need, and it's a little buggy, and I want to learn Python anyway. So I decided to download the <a href="http://juicereceiver.svn.sourceforge.net/viewvc/juicereceiver/trunk/">latest source code</a> and see if I could fix some of the bugs I've noticed and figure out how to extend it to do everything I need.</p>
<p>So step one was just getting to a point where I could compile it. The source code documentation is incomplete, so here's what I did, starting from scratch.</p>
<ol>
<li>Install <a href="http://www.python.org/">Python 2.5.1</a></li>
<li>Install <a href="https://sourceforge.net/projects/pywin32/">pywin32</a> (I'm on Windows)</li>
<li>Install <a href="http://starship.python.net/crew/mhammond/win32/">mfc71.dll</a> (needed by pywin32)</li>
<li>Install <a href="http://www.py2exe.org/">py2exe</a> (needed to compile Python source code to executable bytecode)</li>
<li>Install <a href="http://www.wxpython.org/">wxPython</a> (for the gui)</li>
<li>Install <a href="http://initd.org/tracker/pysqlite/wiki/pysqlite">pysqlite</a> (may not be necessary, but I knew I'd need it eventually)</li>
<li>Install <a href="http://nsis.sourceforge.net/">NSIS</a> (Nullsoft Scriptable Install System)</li>
<li>Install <a href="http://nsis.sourceforge.net/FindProcDLL_plug-in">NSIS FindProcDLL plug-in</a></li>
</ol>
<p>PHEW!</p>
<p><a href='http://yabfog.com/blog/wp-content/uploads/2007/06/juice223djm.gif' title='Juice v.2.2.3.djm'><img src='http://yabfog.com/blog/wp-content/uploads/2007/06/juice223djm.thumbnail.gif' alt='Juice v.2.2.3.djm'/></a> After all of that, it was actually fairly easy to build and install. However, I made the mistake of trying to upgrade the <a href="http://feedparser.org/">Universal Feed Parser</a>, only to find that although Juice would still compile, install and run, it was silently crapping out while trying to read feeds so it would not actually update my podcasts. I reverted back to the version of UFP bundled with Juice and everything was fine (except for the UFP bugs I was hoping to have solved by using a later version, of course).</p>
<p>I should update this as things progress.</p>
]]></content:encoded>
			<wfw:commentRss>http://yabfog.com/blog/2007/06/21/juice-y-python/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://yabfog.com/blog/wp-content/uploads/2007/06/juice223djm.thumbnail.gif" />
		<media:content url="http://yabfog.com/blog/wp-content/uploads/2007/06/juice223djm.thumbnail.gif" medium="image">
			<media:title type="html">Juice v.2.2.3.djm</media:title>
		</media:content>
	</item>
	</channel>
</rss>
