<?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; bit.ly</title>
	<atom:link href="http://www.chrishannam.co.uk/category/bitly/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrishannam.co.uk</link>
	<description>just me</description>
	<lastBuildDate>Wed, 05 May 2010 11:40:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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>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 python

import twitter
import [...]]]></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>Twitter Bot using bit.ly</title>
		<link>http://www.chrishannam.co.uk/2009/02/twitter-bot-using-bitly/</link>
		<comments>http://www.chrishannam.co.uk/2009/02/twitter-bot-using-bitly/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 20:49:53 +0000</pubDate>
		<dc:creator>channam</dc:creator>
				<category><![CDATA[bit.ly]]></category>

		<guid isPermaLink="false">http://www.chrishannam.co.uk/?p=124</guid>
		<description><![CDATA[On the back of my App Engine bit.ly library I have created Deal Chimp. Hes a twitter bot that updates from UK Hot Deals RSS feed so that you can keep up with the bargains.
]]></description>
			<content:encoded><![CDATA[<p>On the back of my App Engine bit.ly library I have created <a href="http://twitter.com/dealchimp">Deal Chimp</a>. Hes a twitter bot that updates from <a href="http://www.hotukdeals.com/rss/hot">UK Hot Deals </a>RSS feed so that you can keep up with the bargains.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishannam.co.uk/2009/02/twitter-bot-using-bitly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>bit.ly Competition Entry</title>
		<link>http://www.chrishannam.co.uk/2009/01/bitly-competition-entry/</link>
		<comments>http://www.chrishannam.co.uk/2009/01/bitly-competition-entry/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 23:35:40 +0000</pubDate>
		<dc:creator>channam</dc:creator>
				<category><![CDATA[App Engine]]></category>
		<category><![CDATA[bit.ly]]></category>

		<guid isPermaLink="false">http://www.chrishannam.co.uk/?p=100</guid>
		<description><![CDATA[Below is the raw code to make a Google App Engine application with the really basic bit.ly api. Theres currently no error checking etc.
If you just want the functionality use the BitLy class in your App Engine code. Currently is just returns simple for you to use. So for example with shorten to access the [...]]]></description>
			<content:encoded><![CDATA[<p>Below is the raw code to make a Google App Engine application with the really basic bit.ly api. Theres currently no error checking etc.</p>
<p>If you just want the functionality use the BitLy class in your App Engine code. Currently is just returns simple for you to use. So for example with shorten to access the the hash you would use: json['results'][urlentered]['hash']. Replace the url entered with the url you supplied.</p>
<p>Any questions please email ch at chrishannam dot co dot uk</p>
<pre name="code" class="python">
import cgi

from django.utils import simplejson

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from google.appengine.api import urlfetch

class Index(webapp.RequestHandler):
	def get(self):

		EXPAND = "expand"
		SHORTEN = "shorten"
		INFO = "info"
		STATS = "stats"
		ERRORS = "errors"

		bitly = BitLy('your_login','your_apikey')

		self.response.out.write('')
		self.response.out.write(bitly.expand('31IqMl'))
		self.response.out.write(bitly.shorten('http://www.chrishannam.co.uk'))
		self.response.out.write(bitly.info('31IqMl'))
		self.response.out.write(bitly.stats('http://bit.ly/31IqMl'))
		self.response.out.write(bitly.errors())
		self.response.out.write('')

class BitLy():
	def __init__(self, login, apikey):
		self.login = login
		self.apikey = apikey

	def expand(self,param):
		request = "http://api.bit.ly/expand?version=2.0.1&amp;shortUrl=http://bit.ly/"
		request += param
		request += "&amp;login=" + self.login + "&amp;apiKey=" +self.apikey

		result = urlfetch.fetch(request)
		json = simplejson.loads(result.content)
		return json

	def shorten(self,param):
		url = "http://" + param
		request = "http://api.bit.ly/shorten?version=2.0.1&amp;longUrl="
		request += url
		request += "&amp;login=" + self.login + "&amp;apiKey=" +self.apikey

		result = urlfetch.fetch(request)
		json = simplejson.loads(result.content)
		return json

	def info(self,param):
		request = "http://api.bit.ly/info?version=2.0.1&amp;hash="
		request += param
		request += "&amp;login=" + self.login + "&amp;apiKey=" +self.apikey

		result = urlfetch.fetch(request)
		json = simplejson.loads(result.content)
		return json

	def stats(self,param):
		request = "http://api.bit.ly/stats?version=2.0.1&amp;shortUrl="
		request += param
		request += "&amp;login=" + self.login + "&amp;apiKey=" +self.apikey

		result = urlfetch.fetch(request)
		json = simplejson.loads(result.content)
		return json

	def errors(self):
		request += "http://api.bit.ly/errors?version=2.0.1&amp;login=" + self.login + "&amp;apiKey=" +self.apikey

		result = urlfetch.fetch(request)
		json = simplejson.loads(result.content)
		return json

application = webapp.WSGIApplication(
                                     [('/', Index)],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishannam.co.uk/2009/01/bitly-competition-entry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
