Archive for the 'Computers' Category

twitpie: Twitter Commandline Client

Jun 16, 2008 in Internet, Programming, Python

A simple need, solved in a simple way - a twitter client for those wanting command-line access and auto-refresh + posting tweets from the same place. It does not implement anything fancy. Just the basic features.

You can choose to expand on the source code and/or leave comments so that I can update it and let everyone else also enjoy a better client.

#!/usr/bin/env python
#
#           twitpie
#
#           Twitter Command Line Client
#
#           A simplistic client useful to get a auto-refreshed feed of your
#           + friends timeline and to post tweets.
#
#
# Author:   Harshad Sharma
#           http://www.twitter.com/hiway
#           harshad (dot) sharma @ gmail (dot) com
#
#
# Usage:    Edit this file --> put in username and password
#           Start program "python twit.py" - it will automatically start showing
#           the latest tweets. To update or quit, press Ctrl+C
#           Type in a tweet and press enter to post the update.
#           simply type 'q' to quit.
#
# Dependency:
#           http://pypi.python.org/pypi/python-twitter/
#
# License:
#           This program is free software: you can redistribute it and/or modify
#           it under the terms of the GNU General Public License as published by
#           the Free Software Foundation, either version 3 of the License, or
#           (at your option) any later version.
#
#           This program is distributed in the hope that it will be useful,
#           but WITHOUT ANY WARRANTY; without even the implied warranty of
#           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#           GNU General Public License for more details.
#
#           You should have received a copy of the GNU General Public License
#           along with this program.  If not, see .

import twitter
import time

# Add your username and password here…
api = twitter.Api(username=’twitterusername’, password=’twitterpassword’)     # <--- EDIT HERE

version = 0.1
finished = False

# Loop till finished is changed to True
while finished == False:
    try:
        # Create an empty list.
        tweets = []

        # iterate throgh the friends timeline and gather data.
        for i in api.GetFriendsTimeline():

            #-------- Choose your fave formatting: --------
            # keep only one line uncommented at a time.

            #tweets.append( "%s (%s) \n%s\n" %(i.user.name, i.relative_created_at, i.text))
            #tweets.append( "%s | %s (%s)\n" %(i.user.name, i.text, i.relative_created_at))
            #tweets.append( "(%s) %s" %(i.user.name, i.text))
            #tweets.append( "%s: %s" %(i.user.name, i.text))
            tweets.append( "%s\n%s\n" %(i.user.name, i.text))

        # Since we want the latest tweets to appear near the prompt instead of
        # scrolling up... (if you want it the other way round, comment the line)
        tweets.reverse()

        # Iterate over the list and print
        for tweet in tweets:
            print tweet

        # Wait for some time...
        time.sleep(3*60) # 3*60 = 3 minutes

    except KeyboardInterrupt: # If user presses Ctrl-C, do the following:

        # Get imput - either tweet or command to exit.
        tweet = raw_input("\n\nWhat are you doing (q=quit | r=refresh): ")

        if tweet.lower() == 'q':
            # Exit loop by setting the flag
            finished = True
        if tweet.lower() == 'r':
            pass
        else:
            # User wants to post a tweet... do it :-)
            api.PostUpdate(tweet)

Artificial Intelligence + Artificial Emotions

May 17, 2008 in Computers, Programming, Python, news

Back in 2003 I was fascinated by a story published in the Reader’s Digest book called “How did it Really Happen?”. It was of the Russian Grand Duchess, Anastasia Romanova. In short, princess Ana. When I researched on the Internet about who she was like, a lot of references came up, some documentation was available and a lot of fan sites were ready to tell how it must have been to know the young princess in person.

An idea took root - I was already creating small chat-bots, software which imitates human conversations, after learning a few tricks from ALICE. My addition to the trick was simple - instead of complex parsing mechanisms was using simple SQL statements to emulate the basic functioning of an AI chat-bot.

I wanted to go a step further and add emotion to my software; however artificial it may be. My attempts either failed or I gave up a bit too soon. This idea was a skeleton in my closet that just wouldn’t keep quiet. It was feeling sad that I had neglected it. Machines could be much more interesting if they had some emotions… I always wondered how it would feel to make a machine happy, angry or sad… and live with the consequences!

Fortunately inspiration came again when a bunch of Indian techies decided to gather up in an IRC channel to discuss things. We wanted a ‘bot’ to manage user permissions and to log parts of the conversation. That was fulfilled pretty soon, but I was getting the itch to write a bot that listened to people’s conversations and would chip in with helpful hints if someone asked a question that was frequently answered.

I made the software and was testing it… but I wasn’t happy… wanted to do something else with it. I realized that my old project was taking over me again. I decided to give in and challenged myself to start and create the first prototype of the software within 32 hours. Technically I failed again - When I was about 8 hours into the project, another project that I had worked on needed some urgent modifications. That resulted in 24 hours lost. Continued after that and managed to finish the project within next 24 hours.

Finally after almost five years of thinking about an idea, I had it in my hands! I was searching for a name fo rthe software, soemthing to identify it with. After going through baby-names lists, and checking username availability and trying to find the easiest name to spell and type, I finally settled for “Hema”, its an Indian name which means “golden”.

Now, Hema can understand when you are praising her, or when you call her stupid… and her mood changes accordingly. She even stops saying the cheerful “Hey!” if you say “Hi!” when she’s in a bad mood. Its fun to cheer her up and get her talking again.

I’m working on some documentation and introduction/demo that I can present to all of you. I currently have a lot of commitments that demand priority treatement. Like always, the pet project must wait a bit more.

Updates about Hema will be posted on this blog and on my twitter account, so if you are interested, watch these spaces.

Catch ya’ll soon…

Google Speaks Hindi!

May 03, 2008 in Computers, Internet, news

I happened to browse to Google’s Language tools today, and I was in for a surprise - it offered me to translate from English to Hindi and back from Hindi to English!

If you know it already, no fun, but since I had not checked it recently, it came as quite a surprise! Here’s my Twitter page… all tweets translated by google.

Twitter translated to Hindi by google language tools

Isn’t it fun?

I’m happy that a lot more people from my country will be able to browse the Internet and understand the content in their own language. Go Google!

Link: http://translate.google.com/translate

And The Reason is… Twitter!

Apr 29, 2008 in Computers, Internet

I’ve been addicted to Twitter for past few months. Signed up during the early few days of twitter, but never happened to use it much - none of my friends were ready to spend 5 INR per text message (SMS) and send messages saying what they were doing at any given time.

Later, using twitter from the web became more common instead of costly messages… still no sign!

Then finally, after almost a year, there was a surge in Indian twitter users, and the place became chatty, twittery even! With the number of people rising, I too got involved in conversations… and before I knew it, I was looking forward to waking up early in the morning to catch up with all the tweets of the office-going tweeters on my list!! This was a drastic change in habit that *nothing* had been able to induce till date.

Peer pressure - no, nobody asked me to wake up. Eagerness to keep up with interesting people - absolutely yes!

Thank you Twitter for making me a early to bed early to rise geek! :-P Now I can enjoy the day and enjoy company of geeks at the same time!

P.S. You can follow my updates here: http://twitter.com/hiway