<?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>Yak Shaving &#187; code</title>
	<atom:link href="http://www.chrishannam.co.uk/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrishannam.co.uk</link>
	<description>just me</description>
	<lastBuildDate>Wed, 14 Dec 2011 12:13:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Debugging Rails</title>
		<link>http://www.chrishannam.co.uk/2011/03/debugging-rails/</link>
		<comments>http://www.chrishannam.co.uk/2011/03/debugging-rails/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 22:50:08 +0000</pubDate>
		<dc:creator>channam</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chrishannam.co.uk/?p=355</guid>
		<description><![CDATA[So in my pursuit of the RoR I thought I would share the process for debugger using Ruby 1.9.* Running/Installing the Debugger Start the server: $ rails server --debugger The following might appear: $ rails server --debugger => Booting WEBrick => Rails 3.0.5 application starting in development on http://0.0.0.0:3000 => Call with -d to detach [...]]]></description>
			<content:encoded><![CDATA[<p>So in my pursuit of the RoR I thought I would share the process for debugger using Ruby 1.9.*</p>
<h2>Running/Installing the Debugger</h2>
<p>Start the server:</p>
<pre class="brush: bash; ruler: true;">
$ rails server --debugger
</pre>
<p>The following might appear:</p>
<pre class="brush: bash; ruler: true;">
$ rails server --debugger

=> Booting WEBrick
=> Rails 3.0.5 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
Exiting
</pre>
<p>If so install the debug gem thus:</p>
<pre class="brush: bash; ruler: true;">
sudo gem install ruby-debug19
</pre>
<p>The 19 is important as without it you will receive the following error:</p>
<pre class="brush: bash; ruler: true;">
$ sudo gem install ruby-debug
Building native extensions.  This could take a while...
ERROR:  Error installing ruby-debug:
	ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
Can't handle 1.9.x yet
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/usr/bin/ruby1.9.1

Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/linecache-0.43 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/linecache-0.43/ext/gem_make.out
</pre>
<p>Now enable the 1.9 gem, by uncommenting line 18 (at least in my file):</p>
<pre class="brush: bash; ruler: true;">
gem 'ruby-debug19', :require => 'ruby-debug'
</pre>
<p>To use the newly installed debugger fire up the server:</p>
<pre class="brush: bash; ruler: true;">
$ rails server --debugger
</pre>
<h2>Debugging</h2>
<p>To pause the executing code add debugger to pause the running server and drop you into an interactive shell.</p>
<pre class="brush: ruby; ruler: true;">
class HomeController < ApplicationController
  def index
    @events = 'meh!'
    debugger
  end
end
</pre>
<p>Causes the following in the terminal running the server:</p>
<pre class="brush: bash; ruler: true;">
$ rails server --debugger
=> Booting WEBrick
=> Rails 3.0.5 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
=> Debugger enabled
[2011-03-05 22:46:53] INFO  WEBrick 1.3.1
[2011-03-05 22:46:53] INFO  ruby 1.9.2 (2010-08-18) [x86_64-linux]
[2011-03-05 22:46:53] INFO  WEBrick::HTTPServer#start: pid=4461 port=3000
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_controller/metal/implicit_render.rb:5
default_render unless response_body
(rdb:2)
</pre>
<p>You can then call methods to inspect the current code. </p>
<p>This is a lovely solution and compared to having to buy an IDE to get a similar debugging functionality (yes, yes pdb, but meh) in Python this is pure win. As usual Ruby Guides have an excellent run down tutorial at <a href="http://guides.rubyonrails.org/debugging_rails_applications.html">http://guides.rubyonrails.org/debugging_rails_applications.html</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishannam.co.uk/2011/03/debugging-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Ruby on Rails on 1.9.2 on Ubuntu</title>
		<link>http://www.chrishannam.co.uk/2011/03/getting-ruby-on-rails-on-1-9-2-on-ubuntu/</link>
		<comments>http://www.chrishannam.co.uk/2011/03/getting-ruby-on-rails-on-1-9-2-on-ubuntu/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 23:36:26 +0000</pubDate>
		<dc:creator>channam</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.chrishannam.co.uk/?p=350</guid>
		<description><![CDATA[So thought it was time to upgrade and start Ruby on Rails on the latest stable version. First problem I hit was the latest Rails packaged for Ubuntu Maverick is 1.8 Ruby. So if you don&#8217;t mind being behind its fine. What follows is how to get the latest greatest Rails on 1.9.2 Ruby. sudo [...]]]></description>
			<content:encoded><![CDATA[<p>So thought it was time to upgrade and start Ruby on Rails on the latest stable version. First problem I hit was the latest Rails packaged for Ubuntu Maverick is 1.8 Ruby. So if you don&#8217;t mind being behind its fine.</p>
<p>What follows is how to get the latest greatest Rails on 1.9.2 Ruby.</p>
<pre class="brush: bash; ruler: true;">
sudo apt-get install ruby1.9.1-full
</pre>
<p>This gets you latest packaged Ruby, note its 1.9.1. After install you will have no &#8220;ruby&#8221; command so symlink up ruby to the actual binary thus:</p>
<pre class="brush: bash; ruler: true;">
$ ruby --version
The program 'ruby' is currently not installed.  You can install it by typing:
sudo apt-get install ruby
$ ruby1.9.1 --version
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
$ sudo ln -s /usr/bin/ruby1.9.1 /usr/bin/ruby
$ ruby --version
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
</pre>
<p>Now we are rocking the latest Ruby using the command ruby.</p>
<p>Next install gems from <a href="http://production.cf.rubygems.org/rubygems/rubygems-1.6.0.tgz">rubygems-1.6.0.tgz</a>. Download and run the installer:</p>
<pre class="brush: bash; ruler: true;">
$ wget http://production.cf.rubygems.org/rubygems/rubygems-1.6.0.tgz
$ tar xvzf rubygems-1.6.0.tgz
$ cd rubygems-1.6.0
$ sudo ruby setup.rb
$ sudo ln -s /usr/bin/gem1.9.1 /usr/bin/gem
</pre>
<p>Yay all installed. Installer the updater as per the instructions printed in the installer bit:</p>
<pre class="brush: bash; ruler: true;">
$ sudo gem install rubygems-update
Fetching: rubygems-update-1.6.0.gem (100%)
Successfully installed rubygems-update-1.6.0
1 gem installed
Installing ri documentation for rubygems-update-1.6.0...
Installing RDoc documentation for rubygems-update-1.6.0...
$ sudo update_rubygems
RubyGems 1.6.0 installed
</pre>
<p>Finally install rails:</p>
<pre class="brush: bash; ruler: true;">
$ sudo gem install rails
</pre>
<p>Before building your project chances are you need to install sqlite3 deps to head off any bundle errors.</p>
<pre class="brush: bash; ruler: true;">
$ sudo apt-get install libsqlite3-dev
</pre>
<p>This will stop:</p>
<pre class="brush: bash; ruler: true;">
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
</pre>
<p>Now you are ready to roll.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishannam.co.uk/2011/03/getting-ruby-on-rails-on-1-9-2-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django Testing and Fixtures</title>
		<link>http://www.chrishannam.co.uk/2010/11/django-testing-and-fixtures/</link>
		<comments>http://www.chrishannam.co.uk/2010/11/django-testing-and-fixtures/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 21:49:41 +0000</pubDate>
		<dc:creator>channam</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.chrishannam.co.uk/?p=319</guid>
		<description><![CDATA[I am currently refactoring a project I&#8217;m actively developing. The initial development was not test driven but more &#8220;Oooh this is cool, hack, hack hack&#8221;. I&#8217;m quite a fan of the idea of premature optimisation being a bad thing, although sometimes this can be an excuse for laziness. So I find myself refactoring and creating [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently refactoring a project I&#8217;m actively developing. The initial development was not test driven but more &#8220;Oooh this is cool, hack, hack hack&#8221;. I&#8217;m quite a fan of the idea of <a href="http://en.wikiquote.org/wiki/Donald_Knuth#Quotes_about_Donald_Knuth">premature optimisation</a> being a bad thing, although sometimes this can be an excuse for laziness.</p>
<p>So I find myself refactoring and creating tests to prove the new code works. This led me to need <a href="http://docs.djangoproject.com/en/1.2/ref/django-admin/#loaddata-fixture-fixture">fixtures</a> or exmaple data to test against. As I already had data in the database creating said fixtures was a easy task:</p>
<pre class="brush: bash; ruler: true;">
manage.py dumpdata app_name.model_name
</pre>
<p>Where app_name in the name of the application you create in Django and the model name is the defined database object usually in models.py. This command dumps the structure of the object out to the command line in json format. To use it create a fixtures directory in your application directory and add the json file. Or the easy way:</p>
<pre class="brush: bash; ruler: true;">
manage.py dumpdata app_name.model_name > fixtures/fixtures.json
</pre>
<p>The file name doesn&#8217;t matter.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishannam.co.uk/2010/11/django-testing-and-fixtures/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SimpleGeo</title>
		<link>http://www.chrishannam.co.uk/2010/04/simplegeo/</link>
		<comments>http://www.chrishannam.co.uk/2010/04/simplegeo/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 19:56:49 +0000</pubDate>
		<dc:creator>channam</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[simplegeo]]></category>

		<guid isPermaLink="false">http://www.chrishannam.co.uk/?p=266</guid>
		<description><![CDATA[While pottering about I found SimpleGeo. I&#8217;m still struggling a little for a use case for this. It&#8217;s cool and that&#8217;s enough for me, yes I am that fickle. Its a simple enough idea and well implemented. You sign up for free. The free account gives you a single &#8220;layer&#8221;. A layer is a collection [...]]]></description>
			<content:encoded><![CDATA[<p>While pottering about I found <a href="http://simplegeo.com/">SimpleGeo</a>.</p>
<p>I&#8217;m still struggling a little for a use case for this. It&#8217;s cool and that&#8217;s enough for me, yes I am that fickle.</p>
<p>Its a simple enough idea and well implemented. You sign up for free. The free account gives you a single &#8220;layer&#8221;. A layer is a collection of data points that you wish to map. Paid for accounts allow more layers but as I&#8217;m only playing I&#8217;m not about to find out. Python is well supported but not very well documented.</p>
<p><a href="http://help.simplegeo.com/faqs/api-documentation/clients-and-example-code">http://help.simplegeo.com/faqs/api-documentation/clients-and-example-code</a> contains what you need to get the libs downloaded and running. From here on I&#8217;m going to assume you have got it installed and running.</p>
<p>Creating a record:</p>
<pre class="brush: python; ruler: true;">
from simplegeo import Record
r = Record('layername', '1', '53.762282', '-0.355662')
r
<simplegeo.Record object at 0x8dbc9cc>
client.add_record(r)
b = client.add_record(r)
print client.get_record('layername', '1')
{'created': 1270653503, 'geometry':
{'type': 'Point', 'coordinates': [-0.35566199999999998, 53.762281999999999]},
'properties': {'layer': 'layername', 'type': 'object'},
'layerLink': {'href': 'http://api.simplegeo.com/0.1/layer/layername.json'},
'type': 'Feature', 'id': '1', 'selfLink':
{'href': 'http://api.simplegeo.com/0.1/records/layername/1.json'}}
</pre>
<p>The code above creates and saves a record on Simple Geo&#8217;s servers and fetches the same record. Its all pretty simple stuff. Where it gets cool is using get_nearby. This allows you to send a location and get back all data points near that location.</p>
<pre class="brush: python; ruler: true;">
print client.get_nearby(layer='layername',arg='53.762281,-0.3456')
{'type': 'FeatureCollection', 'features': [
{'distance': 355.3372151292516, 'created': 1270659182, 'geometry':
{'type': 'Point', 'coordinates': [-0.35099999999999998, 53.762281999999999]},
'properties': {'layer': 'layername', 'type': 'place'}, 'layerLink':
{'href': 'http://api.simplegeo.com/0.1/layer/layername.json'},
'type': 'Feature', 'id': '1', 'selfLink':
{'href': 'http://api.simplegeo.com/0.1/records/layername/1.json'}},
{'distance': 960.75183289629251, 'created': 1271073482, 'geometry':
{'type': 'Point', 'coordinates': [-0.33100000000000002, 53.762281999999999]},
'properties': {'layer': 'layername', 'type': 'place'},
'layerLink': {'href': 'http://api.simplegeo.com/0.1/layer/layername.json'},
'type': 'Feature', 'id': 'TheAdelphi', 'selfLink':
{'href': 'http://api.simplegeo.com/0.1/records/layername/TheAdelphi.json'}}]}
</pre>
<p>Pushing the coolness a bit further is get_density. This takes a location and using Sky Hooks&#8217; <a href="http://www.skyhookwireless.com/spotrank/index.php">Spot Rank</a> will predict the density of people in the supplied location.</p>
<pre class="brush: python; ruler: true;">
print client.get_density('51.5019', '-0.1189', 'tue')
</pre>
<p>Also worth a mention is the method get_history. This will return the last 20 locations of the record with the supplied id.</p>
<pre class="brush: python; ruler: true;">
print client.get_history('layername', '1')
{'type': 'GeometryCollection', 'geometries': [
{'type': 'Point', 'coordinates': [-0.35099999999999998, 53.762281999999999],
'created': 1270659182},
{'type': 'Point', 'coordinates': [-0.35099999999999998, 53.762281999999999],
'created': 1270659072},
{'type': 'Point', 'coordinates': [-0.35566199999999998, 53.762281999999999],
'created': 1270653503}]}
</pre>
<p>While this is all very cool the only gotcha I have found is that longitude and latitude can be the wrong way round. So if you are getting no hits check the long and lat from get_record are the right way round. This is mentioned in the documentation on the Simple Geo&#8217;s site.</p>
<p>Another super cool feature is the dashboard offered when you login to Simple Geo&#8217;s site. There is a Google maps instance which you can use to find you data on. Handy for debugging.</p>
<p>Due to the almost total lack of documentation I worked out most of the above using source <a href="http://http://github.com/simplegeo/python-simplegeo/blob/master/simplegeo/__init__.py">http://github.com/simplegeo/python-simplegeo/blob/master/simplegeo/__init__.py</a>. Its simple enough to read.</p>
<p>Once I find a use for this I will write up some stuff. In the mean time if you get stuck give me a shout, chances you will be stuck at the same point I was&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishannam.co.uk/2010/04/simplegeo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebDriver and Select Boxes</title>
		<link>http://www.chrishannam.co.uk/2009/09/webdriver-and-select-boxes/</link>
		<comments>http://www.chrishannam.co.uk/2009/09/webdriver-and-select-boxes/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 20:24:59 +0000</pubDate>
		<dc:creator>channam</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.chrishannam.co.uk/?p=258</guid>
		<description><![CDATA[This one had me puzzled for a while as I never took the time to sit down and read the documentation fully&#8230; I decided to look at this again after seeing the issue appear on the WebDriver mailing list. How to you use select and option html elements? Below is Python demo. $ python Python [...]]]></description>
			<content:encoded><![CDATA[<p>This one had me puzzled for a while as I never took the time to sit down and read the documentation fully&#8230; I decided to look at this again after seeing the issue appear on the WebDriver mailing list. How to you use select and option html elements? Below is Python demo.</p>
<pre class="brush: python; ruler: true;">$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; from webdriver_firefox.webdriver import FirefoxLauncher
&gt;&gt;&gt; from webdriver_firefox.webdriver import WebDriver
&gt;&gt;&gt; d = WebDriver()
&gt;&gt;&gt; d.get("http://cassandra.appspot.com/")
&gt;&gt;&gt; e = d.find_elements_by_xpath(
"/html/body/div[@id='container']/div[@id='search']/form[@id='searchForm']/div/select")
&gt;&gt;&gt; r = e[0]
&gt;&gt;&gt; t = r.find_elements_by_tag_name("option")
&gt;&gt;&gt; t
[&lt;webdriver_firefox.webelement.WebElement object at 0x8dd778c&gt;,
&lt;webdriver_firefox.webelement.WebElement object at 0x8dd772c&gt;,
&lt;webdriver_firefox.webelement.WebElement object at 0x8dd77ac&gt;,
&lt;webdriver_firefox.webelement.WebElement object at 0x8dd77ec&gt;]
&gt;&gt;&gt; for i in t:
...     print i.get_text()
...
Artist
Location
last.fm Username
Venue
&gt;&gt;&gt; t[2].set_selected()
&gt;&gt;&gt;</pre>
<p>Now in your WebDriver browser session the option box has changed to &#8220;last.fm Username&#8221;. Excuse the variable names but I wanted to make a note before I lost the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishannam.co.uk/2009/09/webdriver-and-select-boxes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Odd Google App Engine Issue</title>
		<link>http://www.chrishannam.co.uk/2009/05/odd-google-app-engine-issue/</link>
		<comments>http://www.chrishannam.co.uk/2009/05/odd-google-app-engine-issue/#comments</comments>
		<pubDate>Sat, 30 May 2009 20:44:30 +0000</pubDate>
		<dc:creator>channam</dc:creator>
				<category><![CDATA[App Engine]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[gae]]></category>

		<guid isPermaLink="false">http://www.chrishannam.co.uk/?p=217</guid>
		<description><![CDATA[I was having issues getting a url with urlfetch.fetch(url), it kept failing with: [snip] File "/home/channam/Code/python/google_appengine/google/appengine/api/urlfetch.py", line 241, in fetch return rpc.get_result(allow_truncated) File "/home/channam/Code/python/google_appengine/google/appengine/api/urlfetch.py", line 388, in get_result self.check_success(allow_truncated) File "/home/channam/Code/python/google_appengine/google/appengine/api/urlfetch.py", line 356, in check_success raise DownloadError(str(e)) DownloadError: ApplicationError: 2 A little bit of poking found that the issue was caused by having a space [...]]]></description>
			<content:encoded><![CDATA[<p>I was having issues getting a url with urlfetch.fetch(url), it kept failing with:</p>
<pre class="brush: python; ruler: true;">
[snip]
  File "/home/channam/Code/python/google_appengine/google/appengine/api/urlfetch.py", line 241, in fetch
    return rpc.get_result(allow_truncated)
  File "/home/channam/Code/python/google_appengine/google/appengine/api/urlfetch.py", line 388, in get_result
    self.check_success(allow_truncated)
  File "/home/channam/Code/python/google_appengine/google/appengine/api/urlfetch.py", line 356, in check_success
    raise DownloadError(str(e))
DownloadError: ApplicationError: 2
</pre>
<p>A little bit of poking found that the issue was caused by having a space in the url, something which I&#8217;m fairly certain was ok on early versions of GAE. Oh well you live and learn.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishannam.co.uk/2009/05/odd-google-app-engine-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>bit.ly for the win</title>
		<link>http://www.chrishannam.co.uk/2009/03/bitly-for-the-win/</link>
		<comments>http://www.chrishannam.co.uk/2009/03/bitly-for-the-win/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 11:35:47 +0000</pubDate>
		<dc:creator>channam</dc:creator>
				<category><![CDATA[App Engine]]></category>
		<category><![CDATA[bit.ly]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.chrishannam.co.uk/?p=194</guid>
		<description><![CDATA[I got my Google App Engine library featured on the list of entries for bit.ly&#8217;s competition see bit.ly competition. Admittedly its a small bit of code but I hope someone might find a use for it. But I`m still waiting for swag]]></description>
			<content:encoded><![CDATA[<p>I got my Google App Engine library featured on the list of entries for bit.ly&#8217;s competition see <a href="http://blog.bit.ly/post/76203780/bit-ly-api-contest-winners">bit.ly competition</a>. Admittedly its a small bit of code but I hope someone might find a use for it.</p>
<p>But I`m still waiting for swag <img src='http://www.chrishannam.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishannam.co.uk/2009/03/bitly-for-the-win/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Forms in App Engine</title>
		<link>http://www.chrishannam.co.uk/2009/03/forms-in-app-engine/</link>
		<comments>http://www.chrishannam.co.uk/2009/03/forms-in-app-engine/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 10:45:43 +0000</pubDate>
		<dc:creator>channam</dc:creator>
				<category><![CDATA[App Engine]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.chrishannam.co.uk/?p=189</guid>
		<description><![CDATA[A handy hint from an on the ball App Engine fella: how to extend the StringProperty class so that it will render as a password field]]></description>
			<content:encoded><![CDATA[<p>A handy hint from an on the ball App Engine fella: <a href="http://hatcattery.appspot.com/article?id=1">how to extend the StringProperty class so that it will render as a password field</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishannam.co.uk/2009/03/forms-in-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter Bot</title>
		<link>http://www.chrishannam.co.uk/2009/02/twitter-bot/</link>
		<comments>http://www.chrishannam.co.uk/2009/02/twitter-bot/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 14:33:59 +0000</pubDate>
		<dc:creator>channam</dc:creator>
				<category><![CDATA[bit.ly]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.chrishannam.co.uk/?p=143</guid>
		<description><![CDATA[While bored I wrote the following python twitter bot. It gets the rss feed from uk hot deals and then tweets the deals. Its pretty basic as it just checks the top item on the list instead of doing dates and times. It uses python-twitter-0.5. The script is run by cron currently every minute. #!/usr/bin/env [...]]]></description>
			<content:encoded><![CDATA[<p>While bored I wrote the following python twitter bot. It gets the rss feed from uk hot deals and then tweets the deals. Its pretty basic as it just checks the top item on the list instead of doing dates and times. It uses python-twitter-0.5.</p>
<p>The script is run by cron currently every minute.</p>
<pre name="code" class="python">
#!/usr/bin/env python

import twitter
import urllib
from xml.dom import minidom
import simplejson

api = twitter.Api(username='username', password='passwd')

def shorten(param):
	""" Using bit.ly to shorten the url """
	url = param
	request = "http://api.bit.ly/shorten?version=2.0.1&#038;longUrl="
	request += url
	request += "&#038;login=username&#038;apiKey=APIKEY"

	# fire off request for bit.ly
	sock = urllib.urlopen(request)
	json = sock.read()
	sock.close()

	# get the json
	json = simplejson.loads(json)
	return json['results'][url]['shortUrl']

# get the rss feed
sock = urllib.urlopen("http://www.hotukdeals.com/rss/hot")
rss = sock.read()
sock.close()  

# parse the rss into ready xml
xmldoc = minidom.parseString(rss)

# eextract our results
items = xmldoc.getElementsByTagName('item')
result = items[0].getElementsByTagName('title')[0].childNodes[0].nodeValue
result += " " +shorten(items[0].getElementsByTagName('link')[0].childNodes[0].nodeValue)

# open the temp file and read in old value
f = open('/tmp/workfile', 'w+')
existing = f.read()
existing = existing.replace('\n', '')

unicode_result = unicode(result)

# if the new value from the top of the rss feed is different tweet and record it
if unicode_result.encode('utf-8') != existing:
	unicode_string = unicode(result)
	f.write(unicode_string.encode('utf-8'))
	if len(result) > 0:
		api.PostUpdate(result)

f.close()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishannam.co.uk/2009/02/twitter-bot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dbus and Banshee</title>
		<link>http://www.chrishannam.co.uk/2009/02/dbus-and-banshee/</link>
		<comments>http://www.chrishannam.co.uk/2009/02/dbus-and-banshee/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 00:11:26 +0000</pubDate>
		<dc:creator>channam</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.chrishannam.co.uk/?p=130</guid>
		<description><![CDATA[A little old news but fun. Add a track to your play queue using python: import dbus bus = dbus.SessionBus() player_queue = bus.get_object("org.bansheeproject.Banshee", "/org/bansheeproject/Banshee/SourceManager/PlayQueue") player_queue.EnqueueUri("/home/channam/Music/Jonathon Coulton/Code Monkey.mp3",True)]]></description>
			<content:encoded><![CDATA[<p>A little old news but fun. Add a track to your play queue using python:</p>
<pre name="code" class="python">
        import dbus
        bus = dbus.SessionBus()
        player_queue = bus.get_object("org.bansheeproject.Banshee",
        "/org/bansheeproject/Banshee/SourceManager/PlayQueue")
        player_queue.EnqueueUri("/home/channam/Music/Jonathon Coulton/Code Monkey.mp3",True)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishannam.co.uk/2009/02/dbus-and-banshee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

