<?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>Kunal Dua &#187; code</title>
	<atom:link href="http://www.kunaldua.com/blog/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kunaldua.com/blog</link>
	<description>Laziness. Impatience. Hubris.</description>
	<lastBuildDate>Thu, 11 Aug 2011 12:54:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Bespin Gotchas</title>
		<link>http://www.kunaldua.com/blog/2010/06/bespin-gotchas/</link>
		<comments>http://www.kunaldua.com/blog/2010/06/bespin-gotchas/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 11:10:23 +0000</pubDate>
		<dc:creator>Kunal</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[www]]></category>

		<guid isPermaLink="false">http://www.kunaldua.com/blog/2010/06/bespin-gotchas/</guid>
		<description><![CDATA[In case of trouble connecting to Bespin from an external machine, try setting the IP address to 0.0.0.0 Either change the file pavement.py: 62 63 64 65 66 67 68 69 70 71 72 server=Bunch&#40; # set to true to &#8230; <a href="http://www.kunaldua.com/blog/2010/06/bespin-gotchas/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2010/05/get-email-updates-when-your-ip-changes-python-dyndns-update-client/' rel='bookmark' title='Get email updates when your IP changes/ Python DynDns update client'>Get email updates when your IP changes/ Python DynDns update client</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In case of trouble connecting to Bespin from an external machine, try setting the IP address to 0.0.0.0</p>
<p>Either change the file pavement.py:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>62
63
64
65
66
67
68
69
70
71
72
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">server=Bunch<span style="color: black;">&#40;</span>
   <span style="color: #808080; font-style: italic;"># set to true to allow connections from other machines</span>
   address=<span style="color: #483d8b;">&quot;0.0.0.0&quot;</span>,
   port=<span style="color: #483d8b;">&quot;8080&quot;</span>,
   try_build=<span style="color: #008000;">False</span>,
   dburl=<span style="color: #008000;">None</span>,
   async=<span style="color: #008000;">False</span>,
   config_file=path<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;devconfig.py&quot;</span><span style="color: black;">&#41;</span>,
   directory=path<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;../bespinserver/&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">abspath</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,
   clientdir=path.<span style="color: black;">getcwd</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#41;</span>,</pre></td></tr></table></div>

<p>Or pass it as a command line argument:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">paver server.address=0.0.0.0 server.port=<span style="color: #000000;">8080</span> start</pre></div></div>

<p>In case you haven&#8217;t noticed, you can even specify the port to start on i.e. run Bespin on a custom port.</p>
<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.kunaldua.com/blog/2010/06/bespin-gotchas/' addthis:title='Bespin Gotchas '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>

<p>Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2010/05/get-email-updates-when-your-ip-changes-python-dyndns-update-client/' rel='bookmark' title='Get email updates when your IP changes/ Python DynDns update client'>Get email updates when your IP changes/ Python DynDns update client</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kunaldua.com/blog/2010/06/bespin-gotchas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorted, Human Readable file sizes via du</title>
		<link>http://www.kunaldua.com/blog/2010/06/sorted-human-readable-file-sizes-via-du/</link>
		<comments>http://www.kunaldua.com/blog/2010/06/sorted-human-readable-file-sizes-via-du/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 05:14:51 +0000</pubDate>
		<dc:creator>Kunal</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.kunaldua.com/blog/2010/06/sorted-human-readable-file-sizes-via-du/</guid>
		<description><![CDATA[du -d 1 &#124; sort -n &#124; cut -f 2 &#124; xargs du -h -d 0 No related posts.


No related posts.]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-d</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-n</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-h</span> <span style="color: #660033;">-d</span> <span style="color: #000000;">0</span></pre></div></div>

<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.kunaldua.com/blog/2010/06/sorted-human-readable-file-sizes-via-du/' addthis:title='Sorted, Human Readable file sizes via du '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.kunaldua.com/blog/2010/06/sorted-human-readable-file-sizes-via-du/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Get email updates when your IP changes/ Python DynDns update client</title>
		<link>http://www.kunaldua.com/blog/2010/05/get-email-updates-when-your-ip-changes-python-dyndns-update-client/</link>
		<comments>http://www.kunaldua.com/blog/2010/05/get-email-updates-when-your-ip-changes-python-dyndns-update-client/#comments</comments>
		<pubDate>Tue, 11 May 2010 05:15:36 +0000</pubDate>
		<dc:creator>Kunal</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[www]]></category>

		<guid isPermaLink="false">http://www.kunaldua.com/blog/?p=360</guid>
		<description><![CDATA[I use DynDns to map my ISP provided dynamic IP to a static hostname. For some reason, the DynDns provided update clients don&#8217;t always work for me and often leave my hostname pointing to a dead or (worse) someone else&#8217;s &#8230; <a href="http://www.kunaldua.com/blog/2010/05/get-email-updates-when-your-ip-changes-python-dyndns-update-client/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2009/12/reliance-wireless-broadband-auto-login-script/' rel='bookmark' title='Reliance Wireless broadband auto-login (and logout) script(s)'>Reliance Wireless broadband auto-login (and logout) script(s)</a></li>
<li><a href='http://www.kunaldua.com/blog/2005/03/yahoo-mail-reduce-the-spam-you-get/' rel='bookmark' title='Yahoo Mail &#8211; reduce the spam you get*'>Yahoo Mail &#8211; reduce the spam you get*</a></li>
<li><a href='http://www.kunaldua.com/blog/2010/06/bespin-gotchas/' rel='bookmark' title='Bespin Gotchas'>Bespin Gotchas</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I use <a href="http://www.dyndns.com/" target="_blank">DynDns</a> to map my ISP provided dynamic IP to a static hostname. For some reason, the DynDns provided <a href="http://www.dyndns.com/support/clients/" target="_blank">update clients</a> don&#8217;t always work for me and often leave my hostname pointing to a dead or (worse) someone else&#8217;s IP. I decided to take matter into my own hands and write a script that would email me my IP whenever my DHCP lease expired and my ISP issued me a fresh one. This would ensure I know how to reach back home, even if my hostname was pointing to an old IP.</p>
<p>While going through the DynDns API, I realized it was trivial to update the hostname as well, essentially replicating the functionality of the aforementioned client(s). So I decided to add that as well.</p>
<p>I know this functionality can be replicated via curl + sendmail, but Python is my tool of choice, so just live with it. Without further ado, here&#8217;s the script, with an explanation afterwards.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># encoding: utf-8</span>
<span style="color: #483d8b;">&quot;&quot;&quot;
Script to email IP whenever it changes. Also updates DynDns hostname.
Version 1.0
&nbsp;
Created by Kunal Dua on 2010-05-10
http://www.kunaldua.com/blog/?p=360
&nbsp;
This program is free software; you may redistribute it and/or
modify it under the same terms as Python itself.
&quot;&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> send_mail<span style="color: black;">&#40;</span>subject, content<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">smtplib</span>
        <span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">email</span>.<span style="color: black;">mime</span>.<span style="color: black;">text</span> <span style="color: #ff7700;font-weight:bold;">import</span> MIMEText
        SERVER = <span style="color: #483d8b;">&quot;smtpserver&quot;</span>
        PORT = <span style="color: #ff4500;">587</span>  <span style="color: #808080; font-style: italic;">#Use 25 if this doesn't work</span>
        USER = <span style="color: #483d8b;">&quot;username&quot;</span>
        PASS = <span style="color: #483d8b;">&quot;password&quot;</span>
        FROM = <span style="color: #483d8b;">&quot;IPBot &lt;mail@example.com&gt;&quot;</span>
        TO = <span style="color: #483d8b;">&quot;user+folder@example.com&quot;</span>
&nbsp;
        SUBJECT = subject
        TEXT = content
&nbsp;
        message = MIMEText<span style="color: black;">&#40;</span>TEXT<span style="color: black;">&#41;</span>
        message<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Subject'</span><span style="color: black;">&#93;</span> = SUBJECT
        message<span style="color: black;">&#91;</span><span style="color: #483d8b;">'From'</span><span style="color: black;">&#93;</span> = FROM
        message<span style="color: black;">&#91;</span><span style="color: #483d8b;">'To'</span><span style="color: black;">&#93;</span> = TO
&nbsp;
        server = <span style="color: #dc143c;">smtplib</span>.<span style="color: black;">SMTP</span><span style="color: black;">&#40;</span>SERVER, PORT<span style="color: black;">&#41;</span>
        server.<span style="color: black;">login</span> <span style="color: black;">&#40;</span>USER, PASS<span style="color: black;">&#41;</span>
        server.<span style="color: black;">sendmail</span><span style="color: black;">&#40;</span>FROM, TO, message.<span style="color: black;">as_string</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        server.<span style="color: black;">quit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> update_dyndns<span style="color: black;">&#40;</span>theip<span style="color: black;">&#41;</span>:
        USERNAME = <span style="color: #483d8b;">'username'</span>
        PASSWORD = <span style="color: #483d8b;">'password'</span>
        HOSTNAME = <span style="color: #483d8b;">'example.dyndns.org'</span>
&nbsp;
        theurl = <span style="color: #483d8b;">'https://%s:%s@members.dyndns.org/nic/update?hostname=%s&amp;myip=%s&amp;wildcard=NOCHG&amp;mx=NOCHG&amp;backmx=NOCHG'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>USERNAME, PASSWORD, HOSTNAME, theip<span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>
        conn = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>theurl<span style="color: black;">&#41;</span>
        <span style="color: #808080; font-style: italic;">#print conn.read()</span>
        conn.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
        <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib2</span>, <span style="color: #dc143c;">re</span>
        conn = <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://checkip.dyndns.com/'</span><span style="color: black;">&#41;</span>
        data = conn.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        conn.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        m = <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'([0-9]*)(<span style="color: #000099; font-weight: bold;">\.</span>)([0-9]*)(<span style="color: #000099; font-weight: bold;">\.</span>)([0-9]*)(<span style="color: #000099; font-weight: bold;">\.</span>)([0-9]*)'</span>, data<span style="color: black;">&#41;</span>
        currip = m.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
&nbsp;
        lastfile = <span style="color: #483d8b;">&quot;lastip.txt&quot;</span>
        allfile = <span style="color: #483d8b;">&quot;history.txt&quot;</span>
&nbsp;
        theipfile = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>lastfile,<span style="color: #483d8b;">&quot;r&quot;</span><span style="color: black;">&#41;</span>
        lastip = theipfile.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        theipfile.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span> lastip == currip:
                <span style="color: #808080; font-style: italic;">#print &quot;no change needed&quot;</span>
                exit<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
                histfile = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>allfile, <span style="color: #483d8b;">&quot;a&quot;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span>
                thenow = <span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">ctime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                histfile.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>thenow, currip<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                histfile.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                theipfile = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>lastfile,<span style="color: #483d8b;">&quot;w&quot;</span><span style="color: black;">&#41;</span>
                theipfile.<span style="color: black;">write</span><span style="color: black;">&#40;</span>currip<span style="color: black;">&#41;</span>
                theipfile.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                send_mail<span style="color: black;">&#40;</span>currip, <span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span>
                update_dyndns<span style="color: black;">&#40;</span>currip<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<ul>
<li>Lines 17-22 and 39-41 replace with your email and DynDns settings respectively.</li>
<li>Line 22 &#8211; My email provider supports redirecting mails to a folder by simply adding the name of the folder before @ sign. For example user+ipupdates@example.com will deliver mail in folder ipupdates of user@example.com. If your email provider supports this, it&#8217;s a useful trick to prevent these mails from cluttering up your inbox. If not, simply enter your regular email address.</li>
<li>Lines 60-61 initialize 2 files that I use. One is to store the current IP (or the last known IP) and the other is a history of all IP changes. The former is used to compare if the IP has changed since the script was last run and thus if an email needs to be sent + DynDns updated. The latter is not really needed for the script to function properly, and is used to maintain a log of all IP changes &#8211; because you can!</li>
<li>Line 78 &#8211; By default, the subject of the mail is the IP and the body/ text is blank. Feel free to obfuscate your IP if you feel paranoid about sending it in clear text or write sweet nothings to yourself in the body.</li>
<li><strong>Note:</strong> Before you run this script for the first time, create an empty file called lastip.txt in the same directory as the script or the script will fail. I know I could write a trivial check for this, but I leave that as an exercise for the reader.</li>
</ul>
<p>Recommended frequency of running this job via cron/ launchd is 10 minutes.</p>
<p><strong>Update</strong>: (May 27) I am pretty sure the DynDns API is broken in some way because I can&#8217;t get it to update even with this script. The email part is working pretty good for me though!</p>
<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.kunaldua.com/blog/2010/05/get-email-updates-when-your-ip-changes-python-dyndns-update-client/' addthis:title='Get email updates when your IP changes/ Python DynDns update client '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>

<p>Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2009/12/reliance-wireless-broadband-auto-login-script/' rel='bookmark' title='Reliance Wireless broadband auto-login (and logout) script(s)'>Reliance Wireless broadband auto-login (and logout) script(s)</a></li>
<li><a href='http://www.kunaldua.com/blog/2005/03/yahoo-mail-reduce-the-spam-you-get/' rel='bookmark' title='Yahoo Mail &#8211; reduce the spam you get*'>Yahoo Mail &#8211; reduce the spam you get*</a></li>
<li><a href='http://www.kunaldua.com/blog/2010/06/bespin-gotchas/' rel='bookmark' title='Bespin Gotchas'>Bespin Gotchas</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kunaldua.com/blog/2010/05/get-email-updates-when-your-ip-changes-python-dyndns-update-client/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Reliance Wireless broadband auto-login (and logout) script(s)</title>
		<link>http://www.kunaldua.com/blog/2009/12/reliance-wireless-broadband-auto-login-script/</link>
		<comments>http://www.kunaldua.com/blog/2009/12/reliance-wireless-broadband-auto-login-script/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 09:55:51 +0000</pubDate>
		<dc:creator>Kunal</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[india]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[www]]></category>

		<guid isPermaLink="false">http://www.kunaldua.com/blog/?p=330</guid>
		<description><![CDATA[The old &#8220;curl&#8221; based method stopped working yesterday when Reliance got a new login page as well as a new backend. It seems Reliance is now also looking at Cookies during authentication. Here&#8217;s a little Python script that you can &#8230; <a href="http://www.kunaldua.com/blog/2009/12/reliance-wireless-broadband-auto-login-script/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2010/05/get-email-updates-when-your-ip-changes-python-dyndns-update-client/' rel='bookmark' title='Get email updates when your IP changes/ Python DynDns update client'>Get email updates when your IP changes/ Python DynDns update client</a></li>
<li><a href='http://www.kunaldua.com/blog/2005/04/the-internals/' rel='bookmark' title='The internals'>The internals</a></li>
<li><a href='http://www.kunaldua.com/blog/2006/08/reset-system-keychain-password/' rel='bookmark' title='Reset system keychain password'>Reset system keychain password</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>The old &#8220;curl&#8221; based method stopped working yesterday when Reliance got a new login page as well as a new backend. It seems Reliance is now also looking at Cookies during authentication. Here&#8217;s a little Python script that you can execute to automate the process.</p>
<p>If you don&#8217;t know what Python is, you better stick to browser based authentication :-)</p>
<p>Needless to say, you can schedule this script as a cron/ launchd job to run periodically and keep you logged in. That&#8217;s how I use it, which is why the script doesn&#8217;t output anything to prevent unnecessary log &#8220;pollution&#8221;.</p>
<p><strong>Login Script for Python 2.x</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># encoding: utf-8</span>
<span style="color: #483d8b;">&quot;&quot;&quot;
Reliance Login Script for Python 2.x v1.0
&nbsp;
Created by Kunal Dua on 2009-12-18
http://www.kunaldua.com/blog/?p=330
&nbsp;
This program is free software; you may redistribute it and/or
modify it under the same terms as Python itself.
&quot;&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib2</span>, <span style="color: #dc143c;">urllib</span>, <span style="color: #dc143c;">cookielib</span>
&nbsp;
username = <span style="color: #483d8b;">'1111111111111111'</span> <span style="color: #808080; font-style: italic;">#replace the text within quotes with your username</span>
password = <span style="color: #483d8b;">'password'</span>	<span style="color: #808080; font-style: italic;">#replace the text within quotes with your password</span>
&nbsp;
jar = <span style="color: #dc143c;">cookielib</span>.<span style="color: black;">FileCookieJar</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;cookies&quot;</span><span style="color: black;">&#41;</span>
opener = <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">build_opener</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">urllib2</span>.<span style="color: black;">HTTPCookieProcessor</span><span style="color: black;">&#40;</span>jar<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
response = opener.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;http://10.239.89.15/reliance/startportal_isg.do&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
login_data = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlencode</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'userId'</span> : username, <span style="color: #483d8b;">'password'</span> : password, <span style="color: #483d8b;">'action'</span> : <span style="color: #483d8b;">'doLoginSubmit'</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
resp = opener.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://10.239.89.15/reliance/login.do'</span>, login_data<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Update: <strong>Logout Script for Python 2.x</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># encoding: utf-8</span>
<span style="color: #483d8b;">&quot;&quot;&quot;
Reliance Logout Script v1.0
&nbsp;
Created by Kunal Dua on 2009-12-22
http://www.kunaldua.com/blog/?p=323
&nbsp;
This program is free software; you may redistribute it and/or
modify it under the same terms as Python itself.
&quot;&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib2</span>, <span style="color: #dc143c;">cookielib</span>
&nbsp;
jar = <span style="color: #dc143c;">cookielib</span>.<span style="color: black;">FileCookieJar</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;cookies&quot;</span><span style="color: black;">&#41;</span>
opener = <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">build_opener</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">urllib2</span>.<span style="color: black;">HTTPCookieProcessor</span><span style="color: black;">&#40;</span>jar<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
response = opener.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;http://10.239.89.15/reliance/login.do&quot;</span>, timeout=<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
&nbsp;
resp = opener.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://10.239.89.15/reliance/logout.do'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Update: <strong>Login Script for Python 3.x</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># encoding: utf-8</span>
<span style="color: #483d8b;">&quot;&quot;&quot;
Reliance Login Script for Python 3.0 v1.0
&nbsp;
Created by Kunal Dua on 2009-12-30
http://www.kunaldua.com/blog/?p=323
&nbsp;
This program is free software; you may redistribute it and/or
modify it under the same terms as Python itself.
&quot;&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>, http.<span style="color: black;">cookiejar</span>
&nbsp;
username = <span style="color: #483d8b;">'1111111111111111'</span> <span style="color: #808080; font-style: italic;">#replace the text within quotes with your username</span>
password = <span style="color: #483d8b;">'password'</span>	<span style="color: #808080; font-style: italic;">#replace the text within quotes with your password</span>
&nbsp;
jar = http.<span style="color: black;">cookiejar</span>.<span style="color: black;">FileCookieJar</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;cookies&quot;</span><span style="color: black;">&#41;</span>
opener = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">request</span>.<span style="color: black;">build_opener</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">urllib</span>.<span style="color: black;">request</span>.<span style="color: black;">HTTPCookieProcessor</span><span style="color: black;">&#40;</span>jar<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
response = opener.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;http://10.239.89.15/reliance/startportal_isg.do&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
login_data = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">parse</span>.<span style="color: black;">urlencode</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'userId'</span> : username, <span style="color: #483d8b;">'password'</span> : password, <span style="color: #483d8b;">'action'</span> : <span style="color: #483d8b;">'doLoginSubmit'</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
resp = opener.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://10.239.89.15/reliance/login.do'</span>, login_data<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.kunaldua.com/blog/2009/12/reliance-wireless-broadband-auto-login-script/' addthis:title='Reliance Wireless broadband auto-login (and logout) script(s) '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>

<p>Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2010/05/get-email-updates-when-your-ip-changes-python-dyndns-update-client/' rel='bookmark' title='Get email updates when your IP changes/ Python DynDns update client'>Get email updates when your IP changes/ Python DynDns update client</a></li>
<li><a href='http://www.kunaldua.com/blog/2005/04/the-internals/' rel='bookmark' title='The internals'>The internals</a></li>
<li><a href='http://www.kunaldua.com/blog/2006/08/reset-system-keychain-password/' rel='bookmark' title='Reset system keychain password'>Reset system keychain password</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kunaldua.com/blog/2009/12/reliance-wireless-broadband-auto-login-script/feed/</wfw:commentRss>
		<slash:comments>56</slash:comments>
		</item>
		<item>
		<title>echo what you read with IFS</title>
		<link>http://www.kunaldua.com/blog/2009/02/echo-what-you-read-with-ifs/</link>
		<comments>http://www.kunaldua.com/blog/2009/02/echo-what-you-read-with-ifs/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 20:14:17 +0000</pubDate>
		<dc:creator>Kunal</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.kunaldua.com/blog/?p=193</guid>
		<description><![CDATA[Sample this code for reading a file line by line: 1 2 3 4 5 #!/bin/ksh while read LINE do echo &#34;$LINE&#34; done &#60; $FILENAME It works fine in most cases, where by most cases I mean your lines don&#8217;t &#8230; <a href="http://www.kunaldua.com/blog/2009/02/echo-what-you-read-with-ifs/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2005/04/the-internals/' rel='bookmark' title='The internals'>The internals</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Sample this code for reading a file line by line:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/ksh</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> LINE
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$LINE</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$FILENAME</span></pre></td></tr></table></div>

<p>It works fine in most cases, where by most cases I mean your lines don&#8217;t have any trailing spaces that you&#8217;d like to preserve. That&#8217;s right, read reserves the right to kill the trailing (and leading) spaces from your lines. Sample this (from <a href="http://nixdoc.net/man-pages/Linux/ksh.1.html">ksh man page</a>):</p>
<blockquote><p>
The IFS parameter specifies a list of characters which are used to break a string up into several words; any characters from the set space, tab and newline that appear inthe IFS characters are called IFS white space. Sequences of one or more IFS white space characters, in combination with zero or one non IFS white space characters delimit a field. As a special case, leading and trailing IFS white space is stripped (i.e., no leading ortrailing emptyfield is created by it); leading or trailing non-IFS white space does create an empty field.Example: if IFS is set to `<space>:&#8217;,the sequence of characters `<space>A<space>:<space><space>B::D&#8217; contains four fields: `A&#8217;, `B&#8217;, `&#8217; and `D&#8217;. Note that if the IFS parameter is set to the null string, no field splitting is done; if the parameter is unset, the default value of space, tab and newline is used.
</p></blockquote>
<p>So, the above code should be changed to this &#8211; just the one line added:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/ksh</span>
<span style="color: #007800;">IFS</span>=<span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> LINE
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$LINE</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$FILENAME</span></pre></td></tr></table></div>

<p>Now the above code gives the byte-by-byte output of the file. Or does it?</p>
<p>Problem is, if the file does not have an empty line at the end you&#8217;ll see that the last line never shows up in the output! So how do we fix this? The &#8220;old-fashioned&#8221; way &#8211; by adding an extra &#8220;echo $LINE&#8221; outside the loop.</p>
<p>Does it work fine now? Not quite. Now you&#8217;ll see an extra empty line at the end of the output file. How do we fix that? Use  &#8220;echo -n&#8221;. The &#8220;-n&#8221; option tells echo not to print the trailing newline character.</p>
<p>So finally we have our code to read a file line by line, do something with that line and write a modified line &#8211; and preserve every single bit along the way. Here it is then:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/ksh</span>
<span style="color: #007800;">IFS</span>=<span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-r</span> LINE
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$LINE</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$FILENAME</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #007800;">$LINE</span></pre></td></tr></table></div>

<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.kunaldua.com/blog/2009/02/echo-what-you-read-with-ifs/' addthis:title='echo what you read with IFS '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>

<p>Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2005/04/the-internals/' rel='bookmark' title='The internals'>The internals</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kunaldua.com/blog/2009/02/echo-what-you-read-with-ifs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DigitalColor Meter</title>
		<link>http://www.kunaldua.com/blog/2007/10/digitalcolor-meter/</link>
		<comments>http://www.kunaldua.com/blog/2007/10/digitalcolor-meter/#comments</comments>
		<pubDate>Tue, 09 Oct 2007 20:15:26 +0000</pubDate>
		<dc:creator>Kunal</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.kunaldua.com/blog/?p=184</guid>
		<description><![CDATA[I was trying to &#8220;blend&#8221; a widget into the sidebar of this blog. No problem, I thought, I&#8217;ll go to the wonderful Element Inspector, and find out the current background color. I got the RGB value from the Inspector, converted &#8230; <a href="http://www.kunaldua.com/blog/2007/10/digitalcolor-meter/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2005/06/mac-gems-vol-1/' rel='bookmark' title='Mac Gems vol. 1'>Mac Gems vol. 1</a></li>
<li><a href='http://www.kunaldua.com/blog/2009/11/ayrton-diego-get-new-stripes/' rel='bookmark' title='Ayrton, Diego get new stripes'>Ayrton, Diego get new stripes</a></li>
<li><a href='http://www.kunaldua.com/blog/2006/09/album-art-for-the-rest-of-us-v10/' rel='bookmark' title='Album Art For The Rest of Us'>Album Art For The Rest of Us</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I was trying to &#8220;blend&#8221; a widget into the sidebar of this blog. No problem, I thought, I&#8217;ll go to the wonderful <a href="http://www.red-sweater.com/blog/363/webkits-new-element-inspector">Element Inspector</a>, and find out the current background color. I got the RGB value from the Inspector,  converted it to Hex using <a href="http://www.versiontracker.com/dyn/moreinfo/macosx/13967">exColor</a> and sampled it, but the resultant color wasn&#8217;t the sidebar background color at all. The value matched the one specified in the CSS file for the sidebar alright, but the result on-screen  was quite different from how it shows up in the blog! Intriguing.</p>
<p>Obviously, there are some intricacies of CSS at work there which I don&#8217;t quite comprehend at this point (the behaviour is consistent across all browsers). I promise to dig into that later and post my findings around here. However, the show had to go on &#8211; I needed to find out the color being actually displayed on screen and use it! So I set out trying to find a utility that could identify the color of any pixel on screen. On a whim, I typed &#8220;color&#8221; in QuickSilver and stumbled into /Applications/Utilities/DigitalColor Meter.app.</p>
<p>It does just what I said &#8211; tell you the exact value of any pixel on screen in RGB (absolute, percentage or hex) as well as other models. Have it running in the background and move your mouse to the pixel of your choice in any application. Just switch the focus back to DigitalColor Meter and you should see the color value corresponding to the pixel under the mouse pointer in the application last in focus. It has keyboard shortcuts to &#8220;hold&#8221; the current color value or to &#8220;lock&#8221; the focus of the mouse to the current pixel position, as well as copying the current color value to the clipboard &#8211; explore the menus, it&#8217;s quite simple and intuitive, really.</p>
<p>A word of warning though &#8211; do NOT keep it running in the background unnecessarily, not without putting it on hold at the least. Since it keeps updating itself as you move your mouse around and/ or switch applications,  the whole process can take a toll on your CPU usage if done continously for long periods of time.</p>
<p>Another great utility that comes free, pre-installed on your Mac!</p>
<p>PS &#8211; For the record, ths sidebar color specifed is #666666. What you see is #ECFDCE.</p>
<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.kunaldua.com/blog/2007/10/digitalcolor-meter/' addthis:title='DigitalColor Meter '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>

<p>Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2005/06/mac-gems-vol-1/' rel='bookmark' title='Mac Gems vol. 1'>Mac Gems vol. 1</a></li>
<li><a href='http://www.kunaldua.com/blog/2009/11/ayrton-diego-get-new-stripes/' rel='bookmark' title='Ayrton, Diego get new stripes'>Ayrton, Diego get new stripes</a></li>
<li><a href='http://www.kunaldua.com/blog/2006/09/album-art-for-the-rest-of-us-v10/' rel='bookmark' title='Album Art For The Rest of Us'>Album Art For The Rest of Us</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kunaldua.com/blog/2007/10/digitalcolor-meter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The internals</title>
		<link>http://www.kunaldua.com/blog/2005/04/the-internals/</link>
		<comments>http://www.kunaldua.com/blog/2005/04/the-internals/#comments</comments>
		<pubDate>Tue, 05 Apr 2005 18:17:30 +0000</pubDate>
		<dc:creator>Kunal</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[www]]></category>

		<guid isPermaLink="false">http://kunaldua.com/2005/04/05/the-internals/</guid>
		<description><![CDATA[How to get "Now Playing in iTunes" album art on your website <a href="http://www.kunaldua.com/blog/2005/04/the-internals/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2005/04/now-playing/' rel='bookmark' title='Now playing!'>Now playing!</a></li>
<li><a href='http://www.kunaldua.com/blog/2006/09/album-art-for-the-rest-of-us-v10/' rel='bookmark' title='Album Art For The Rest of Us'>Album Art For The Rest of Us</a></li>
<li><a href='http://www.kunaldua.com/blog/2005/03/itunes-shuffle-not-that-random/' rel='bookmark' title='iTunes &#8220;shuffle&#8221; not that random'>iTunes &#8220;shuffle&#8221; not that random</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Carrying forward from yesterday, let&#8217;s take a behind-the-scenes peek at the &#8220;Now Playing in iTunes&#8221; album art feature you see in the sidebar.</p>
<p>Here&#8217;s what you&#8217;ll need: 500 gms Mac OS X (sorry Windows people), 50 gms AppleScript, 2 tbspn Shell Script, 1 tbspn FTP, 1 Amazon developer ID, 250 gms PHP and 1/2 tbsp Cron skills.</p>
<p>Here&#8217;s how it functions. We schedule a <span id="more-37"></span>AppleScript to run every 5 minutes. This AppleScript passes the name, artist and album of the song currently playing in iTunes to a shell script. This shell script FTPs this information to your webserver. The PHP script reads this file, queries the Amazon database using Amazon Web Services and gets the corresponding album art (if any). Simple, isn&#8217;t it?</p>
<p>Le&#8217;ts dig into the code, shall we?</p>
<p>The AppleScript</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
	<span style="color: #ff0033; font-weight: bold;">if</span> player state <span style="color: #ff0033; font-weight: bold;">is</span> paused <span style="color: #ff0033;">or</span> player state <span style="color: #ff0033; font-weight: bold;">is</span> playing <span style="color: #ff0033; font-weight: bold;">then</span>
		<span style="color: #ff0033; font-weight: bold;">copy</span> current track <span style="color: #ff0033; font-weight: bold;">to</span> currTrack
		<span style="color: #ff0033; font-weight: bold;">copy</span> artist <span style="color: #ff0033; font-weight: bold;">of</span> currTrack <span style="color: #ff0033; font-weight: bold;">to</span> currArtist
		<span style="color: #ff0033; font-weight: bold;">set</span> currArtist <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;<span style="color: #000000; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #000000;">&amp;</span> currArtist <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;<span style="color: #000000; font-weight: bold;">\&quot;</span>&quot;</span>
		<span style="color: #ff0033; font-weight: bold;">copy</span> <span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> currTrack <span style="color: #ff0033; font-weight: bold;">to</span> currName
		<span style="color: #ff0033; font-weight: bold;">set</span> currName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;<span style="color: #000000; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #000000;">&amp;</span> currName <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;<span style="color: #000000; font-weight: bold;">\&quot;</span>&quot;</span>
		<span style="color: #ff0033; font-weight: bold;">copy</span> album <span style="color: #ff0033; font-weight: bold;">of</span> currTrack <span style="color: #ff0033; font-weight: bold;">to</span> currAlbum
		<span style="color: #ff0033; font-weight: bold;">set</span> currAlbum <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;<span style="color: #000000; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #000000;">&amp;</span> currAlbum <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;<span style="color: #000000; font-weight: bold;">\&quot;</span>&quot;</span>
		<span style="color: #ff0033; font-weight: bold;">set</span> myCommand <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;~/uploads &quot;</span> <span style="color: #000000;">&amp;</span> currArtist <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> currName <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> currAlbum
		<span style="color: #0066ff;">do shell script</span> myCommand password <span style="color: #009900;">&quot;ADMINPASSWORD&quot;</span> <span style="color: #ff0033; font-weight: bold;">with</span> administrator privileges
	<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span></pre></td></tr></table></div>

<p>It&#8217;s rather self explanatory isn&#8217;t it? The &#8220;\&#8221;" bit is to enclose the string within quotes &#8211; just to be sure. We then call a shell script called &#8220;uploads&#8221; with 3 parameters. I store both the AppleScript and the shell script in my home (~) folder.</p>
<p>The shell script</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>np.txt
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$2</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>np.txt
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$3</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>np.txt
<span style="color: #c20cb9; font-weight: bold;">ftp</span> <span style="color: #660033;">-n</span> yourwebsite.com <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>EOF
user usrname password
put ~<span style="color: #000000; font-weight: bold;">/</span>np.txt <span style="color: #000000; font-weight: bold;">/</span>remote<span style="color: #000000; font-weight: bold;">/</span>directory<span style="color: #000000; font-weight: bold;">/</span>np.txt
bye
EOF</pre></td></tr></table></div>

<p>Again, rather simple. Store the information in a text file and upload it to the remote directory.</p>
<p>Now to querying Amazon and parsing XML. And adding the crontab entry. Nah, all that later, a big Champions League night beckons!</p>
<p>PS &#8211; This is perhaps the simplest of approaches with a LOT of disadvantages &#8211; this is nowhere near the best way of doing this. There&#8217;s something in each of the steps that can be improved &#8211; I&#8217;ll cover all that and more next time.</code></p>
<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.kunaldua.com/blog/2005/04/the-internals/' addthis:title='The internals '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>

<p>Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2005/04/now-playing/' rel='bookmark' title='Now playing!'>Now playing!</a></li>
<li><a href='http://www.kunaldua.com/blog/2006/09/album-art-for-the-rest-of-us-v10/' rel='bookmark' title='Album Art For The Rest of Us'>Album Art For The Rest of Us</a></li>
<li><a href='http://www.kunaldua.com/blog/2005/03/itunes-shuffle-not-that-random/' rel='bookmark' title='iTunes &#8220;shuffle&#8221; not that random'>iTunes &#8220;shuffle&#8221; not that random</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kunaldua.com/blog/2005/04/the-internals/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Now playing!</title>
		<link>http://www.kunaldua.com/blog/2005/04/now-playing/</link>
		<comments>http://www.kunaldua.com/blog/2005/04/now-playing/#comments</comments>
		<pubDate>Mon, 04 Apr 2005 20:46:36 +0000</pubDate>
		<dc:creator>Kunal</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[www]]></category>

		<guid isPermaLink="false">http://kunaldua.com/2005/04/05/now-playing/</guid>
		<description><![CDATA[Long time no see! I don&#8217;t know about you, but I saw so many pranks flying around on April Fools&#8217; Day, that I couldn&#8217;t be sure what&#8217;s for real and what&#8217;s not. For a moment, I was dead sure April &#8230; <a href="http://www.kunaldua.com/blog/2005/04/now-playing/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2005/04/the-internals/' rel='bookmark' title='The internals'>The internals</a></li>
<li><a href='http://www.kunaldua.com/blog/2005/03/itunes-shuffle-not-that-random/' rel='bookmark' title='iTunes &#8220;shuffle&#8221; not that random'>iTunes &#8220;shuffle&#8221; not that random</a></li>
<li><a href='http://www.kunaldua.com/blog/2006/09/album-art-for-the-rest-of-us-v10/' rel='bookmark' title='Album Art For The Rest of Us'>Album Art For The Rest of Us</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Long time no see!</p>
<p>I don&#8217;t know about you, but I saw so many pranks flying around on April Fools&#8217; Day, that I couldn&#8217;t be sure what&#8217;s for real and what&#8217;s not. For a moment, I was dead sure April was going to announce Tiger on the 1st, which happens to be their (Apple&#8217;s) anniversary I&#8217;m told, unless of course that was a smart ass&#8217;s idea of a joke.</p>
<p>Another reason for not much activity around here is <span id="more-36"></span>I&#8217;ve been involved in stuff which will see me join a company from tomorrow &#8211; well a few hours from now actually. Yipeee?</p>
<p>This means you&#8217;ll see some stuff on the lines of &#8220;Lessons I learnt from my entrepreneurial stint&#8221; etc. very shortly.</p>
<p>But you can see the results of what has kept me busy for the best part of this evening right now. A brand new &#8220;Now Playing&#8221; section which displays the album art of the song that&#8217;s currently playing in iTunes on my Powerbook. I&#8217;ve been wanting to do this for a while now &#8211; it&#8217;s a 100% &#8220;home made&#8221; plugin (though technically it isn&#8217;t a wordpress plugin &#8211; yet) &#8211; but only now does it see the light of day.</p>
<p>It&#8217;s kinda &#8220;crude&#8221; right now, but, hey, it does the job! The internal workings and more on it&#8217;s features/ limitations to follow pretty soon &#8211; tomorrow hopefully!</p>
<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.kunaldua.com/blog/2005/04/now-playing/' addthis:title='Now playing! '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>

<p>Related posts:<ol><li><a href='http://www.kunaldua.com/blog/2005/04/the-internals/' rel='bookmark' title='The internals'>The internals</a></li>
<li><a href='http://www.kunaldua.com/blog/2005/03/itunes-shuffle-not-that-random/' rel='bookmark' title='iTunes &#8220;shuffle&#8221; not that random'>iTunes &#8220;shuffle&#8221; not that random</a></li>
<li><a href='http://www.kunaldua.com/blog/2006/09/album-art-for-the-rest-of-us-v10/' rel='bookmark' title='Album Art For The Rest of Us'>Album Art For The Rest of Us</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kunaldua.com/blog/2005/04/now-playing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

