<?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>Rayhan's blog (raynux.com) &#187; Python</title>
	<atom:link href="http://raynux.com/blog/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://raynux.com/blog</link>
	<description>Rayhan's Personal Web Blog Site</description>
	<lastBuildDate>Mon, 11 Apr 2011 06:33:57 +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>Update your social networking status from command line</title>
		<link>http://raynux.com/blog/2009/02/28/update-your-social-networking-status-from-command-line/</link>
		<comments>http://raynux.com/blog/2009/02/28/update-your-social-networking-status-from-command-line/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 07:27:21 +0000</pubDate>
		<dc:creator>rayhan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://raynux.com/blog/?p=61</guid>
		<description><![CDATA[This is my first python script, Throughout the learning process I want to make something use full and I know that the best way to learn a new programming language is to start with some real project. Updating your social networking status is now a frequent job. To make this job easier there are lots [...]]]></description>
			<content:encoded><![CDATA[<p>This is my first python script, Throughout the learning process I want to make something use full and I know that the best way to learn a new programming language is to start with some real project.</p>
<p>Updating your social networking status is now a frequent job. To make this job easier there are lots of web services, desktop applications, mobile applications, plug-ins available to the users. Some people wants to update there status from a single place. Like others <a href="http://ping.fm/">Ping.fm</a>, <a href="http://hellotxt.com/">Hellotxt.com</a> are providing single place service with a variety of options. But I think that updating status from command line is the easiest way for most of the Linux users who loves their terminal.</p>
<p>I have used ping.fm REST API for my script as a result It can update all the services registered with ping.fm at once or a single service putting additional parameter. You just need the Internet connection and terminal to put the command.</p>
<p>File: <strong><em>~/bin/raypm</em></strong></p>
<pre>
<code>#! /usr/bin/env python
"""
A Simple program to update your social networking status using ping.fm

This program will update all your social networking sites via ping.fm.

requirements
	- sign for a account at ping.fm
	- setup ping.fm for desired social networking sites.
	- get your developer api key http://www.ping.fm/developers
	- get your user key from http://www.ping.fm/key

@example
	- shell > raypm "your message text to update your all social networking status, like twitter, facebook, linkedin"
	- shell > raypm twitter "your message text to update twitter status only"
	- shell > raypm facebook "your message text to update facebook status only"

@author		: Md. Rayhan Chowdhury
@email		: ray@raynux.com
@website	: www.raynux.com
@license	: GPL
@copy		: All right are reserved
"""

import urllib
import urllib2
import sys
from xml.etree import ElementTree as ET

# modify __apiKey__ with your own
# get your apiKey from http://www.ping.fm/developers
__apiKey__ = 'YOUR DEVELOPER API KEY HERE' 

# modify __userKey__ with your own user key
# get your user key from http://www.ping.fm/key
__UserKey__ = "YOUR USER APP KEY HERE"

__apiUrl__ = 'http://api.ping.fm/v1/'

# debug
# 1 - will not update your status, dump xml response text
# 0 - will update your status
debug = 0

class RayStatus:

	def __init__(self, msg = None, service = None):
		"create message"    

		global debug

		data = {	'api_key'		: __apiKey__,
					'user_app_key'	: __UserKey__,
					'post_method'	: 'default',
					'body'			: msg,
					'debug'			: debug
                  }
		if service is not None:
			data['service'] = service		

		#Encode the data to be posted
		data = urllib.urlencode(data)	

		print "Loading..."
		# post the data
		req = urllib2.Request(__apiUrl__ + 'user.post', data)
		try:
			response = urllib2.urlopen(req)

			responseXML = response.read()

			# parse response data
			result = ET.XML(responseXML)
			if result.attrib is not None:
				if result.attrib['status'] == 'OK':
					print 'Congratulations! your message posted successfully!';
				else:
					print 'Error: ' + result[2].text

			if debug:
				print
				print "debug info: "
				print responseXML

		except urllib2.URLError, e:
			if hasattr(e, 'reason'):
				print 'Could not connect to the server.'
				print 'Reason: ', e.reason
			elif hasattr(e, 'code'):
				print 'The server couldn\'t fulfill the request.'
				print 'Error code: ', e.code
		else:
			print

if __name__ == '__main__':
	try:
		if (len(sys.argv) == 2):
			RayStatus(sys.argv[1], None)
		elif (len(sys.argv) == 3):
			RayStatus(sys.argv[2], sys.argv[1])
	except IndexError:
		print "Please enter your desired message to be posted."
</code></pre>
<p>To make the script working, you need to sign up for a <a href="http://ping.fm">ping.fm</a> user account, and registrar for services you want, they support all major social networking sites including <a href="http://www.twitter.com">twitter</a>, <a href="http://www.facebook.com">facebook</a>, <a href="http://www.linkedin.com">linkedIn</a>. </p>
<p>You will need to get these two keys.<br />
- developer api_keys from <a href="http://ping.fm/developers/">http://ping.fm/developers/</a><br />
- user app key from  <a href="http://ping.fm/key/">http://ping.fm/key/</a></p>
<p>I have my developer api key from <a href="http://ping.fm/">ping.fm</a> which will work for you, but I can&#8217;t disclose it openly. It will be great to have your own api key  and user key is unique for each user. </p>
<p>Installation:</p>
<ol>
<li>create a directory inside your home folder named <strong>bin</strong></li>
<li>create a file named <strong>raymp</strong> inside the bin folder and copy and paste the code</li>
<li>replace <strong>api key</strong> and <strong>user key</strong> with your own.</li>
<li>make the file executable with this command<br />
                <code># chmod +x ~/bin/raypm</code></li>
<li>you may need to restart the system to add the newly added bin folder to PATH.</li>
</ol>
<p>&#038; done.</p>
<p>now you can update your status with the following commands<br />
<code># raypm "update all social networking status at once"</code><br />
or<br />
<code># raypm twitter "update twitter status only"</code><br />
or<br />
<code># raypm facebook "update facebook status only"</code></p>
]]></content:encoded>
			<wfw:commentRss>http://raynux.com/blog/2009/02/28/update-your-social-networking-status-from-command-line/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>I have started learning both Ruby &amp; Python</title>
		<link>http://raynux.com/blog/2008/07/15/i-have-started-learning-both-ruby-python/</link>
		<comments>http://raynux.com/blog/2008/07/15/i-have-started-learning-both-ruby-python/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 17:58:38 +0000</pubDate>
		<dc:creator>rayhan</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://raynux.com/blog/?p=35</guid>
		<description><![CDATA[Today I have started learning Python, after a successful start I have found that in Python the code block is separated by indent. That means no closing braces or ending identifier. like def whats_on_the_telly(penguin=None): if penguin is None: penguin = [] penguin.append("property of the zoo") return penguin &#160; def another_func(): return 1 Here, the function [...]]]></description>
			<content:encoded><![CDATA[<p>Today I have started learning Python, after a successful start I have found that in Python the code block is separated by indent. That means no closing braces or ending identifier. like</p>
<pre>
<code>
def whats_on_the_telly(penguin=None):
    if penguin is None:
        penguin = []
    penguin.append("property of the zoo")
    return penguin
 &nbsp;
def another_func():
    return 1
</code>
</pre>
<p>Here, the function definition ends at after a blank line followed by another definition. I was disappointed with this features of Python and found it is confusing for a large code base for manageability. </p>
<p>As a result I moved to Ruby. After installing Ruby in my PC I started learning the basics of Ruby Language. I have found some interesting features in Ruby language. But I am not impressed with some features like the way of return statement in a function definition. </p>
<p>This is my opinion as a beginner. Yet, I want to try both of them. </p>
]]></content:encoded>
			<wfw:commentRss>http://raynux.com/blog/2008/07/15/i-have-started-learning-both-ruby-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

