<?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>Fellinghaug Blog &#187; twitter</title>
	<atom:link href="http://asbjorn.fellinghaug.com/blog/tag/twitter/feed/" rel="self" type="application/rss+xml" />
	<link>http://asbjorn.fellinghaug.com/blog</link>
	<description>&#62;&#62;&#62; from fellinghaug import asbjorn; asbjorn.play()</description>
	<lastBuildDate>Thu, 19 Nov 2009 21:22:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Twitter from commandline</title>
		<link>http://asbjorn.fellinghaug.com/blog/2008/05/twitter-from-commandline/</link>
		<comments>http://asbjorn.fellinghaug.com/blog/2008/05/twitter-from-commandline/#comments</comments>
		<pubDate>Mon, 05 May 2008 19:26:44 +0000</pubDate>
		<dc:creator>Asbjørn Alexander Fellinghaug</dc:creator>
				<category><![CDATA[Funny]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lucene]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://asbjorn.fellinghaug.com/blog/?p=24</guid>
		<description><![CDATA[I&#8217;ve been taken by the Twitter storm these days.. Damn, I should focus a hole lot more on my master report. Well, this took me only one little hour, so it&#8217;s not that waste of time..    So, I guess you have heard about the new &#8220;facebook&#8221; called Twitter? Well, its this new [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been taken by the Twitter storm these days.. Damn, I should focus a hole lot more on my master report. Well, this took me only one little hour, so it&#8217;s not that waste of time.. <img src='http://asbjorn.fellinghaug.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   So, I guess you have heard about the new &#8220;facebook&#8221; called <a title="Twitter" href="http://www.twitter.com">Twitter</a>? Well, its this new web community thing were people can write their current status for what they are doing in the world.. And, of course, one can follow friends and pay attention to were / what they are doing.. Now, after some time I found it rather heavy to enter the twitter webpage, login, and then post a new twitter message for each time I want to update my status. So, as a python fan I am, I created myself a little python script to capture this problem. It relies on the <a title="Python Twitter" href="http://code.google.com/p/python-twitter/">python-twitter</a> module available at the Google Code pages. So, lets have a look at the code. I have named this file &#8220;update.py&#8221;, however feel free to rename it.</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
</pre></td><td class="code"><pre class="python python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #ff7700;font-weight:bold;">import</span> twitter
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
USERNAME=<span style="color: #483d8b;">&quot;&quot;</span>
PASSWORD=<span style="color: #483d8b;">&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> postNewMessage<span style="color: black;">&#40;</span>msg<span style="color: black;">&#41;</span>:
    api = twitter.<span style="color: black;">Api</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    api = twitter.<span style="color: black;">Api</span><span style="color: black;">&#40;</span>username=<span style="color: #483d8b;">&quot;&quot;</span>, password=<span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">isinstance</span><span style="color: black;">&#40;</span>msg, <span style="color: #008000;">list</span><span style="color: black;">&#41;</span>:
        msg = <span style="color: #483d8b;">&quot; &quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>msg<span style="color: black;">&#41;</span>
    msg = <span style="color: #008000;">unicode</span><span style="color: black;">&#40;</span>msg, <span style="color: #483d8b;">&quot;utf-8&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>msg<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">140</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;ERROR: Message can't be over 140 chars.&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
        api.<span style="color: black;">PostUpdate</span><span style="color: black;">&#40;</span>msg<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;OK. Was %i chars in msg.&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>msg<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">Exception</span>, e:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;FUck..&quot;</span>
&nbsp;
    api.<span style="color: black;">ClearCredentials</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">1</span>:
        t = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span> == <span style="color: #ff4500;">1</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>t<span style="color: black;">&#91;</span>0<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">10</span>:
            <span style="color: #808080; font-style: italic;"># writes ./update &quot;hi there mate&quot;</span>
            postNewMessage<span style="color: black;">&#40;</span>t<span style="color: black;">&#91;</span>0<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #808080; font-style: italic;"># writes ./update hello world</span>
            postNewMessage<span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;fuck&quot;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://asbjorn.fellinghaug.com/blog/2008/05/twitter-from-commandline/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
