Image 01 Image 02

2
Posted on 15th December 2007 by Taggy

yes,its pretty exciting now .My restlessness in holidays gave rise to a small hack,the twitter hack ,twitter.com/meninblue ( update: The scores and commentary was taken from their wap feed ) .Shortly after i released it ,i got a hello mail from Krishna Vedati ,the CEO of a silicon valley startup and they kindof liked my little hack and asked me if you could do some for them .

People who know me know it well,the word startup excites me for it allows

  • one to work with things that are close to his heart
  • Write production ready code overnight and see people use it the next morning
  • And best to work with people who are smart and will help you become smarter
  • Get paid to do what you love to do and learn to do the same in a better way
  • yeah the place is silicon valley the *hottest* technology bed

i told him i would love to and checking out their widgets page at plusmo ,i see a huge list of existing widgets and now i get to add some :) and hopefully ones that people will love to use and keep it on their phones.

Ok,its not for this announcement that iam making this post ,i wanted to put a few things

I told you how i landed with this oppurtunity ,a little idea ,one that people will *use* it and working with the latest in thing .

In my case twitter and cricket action that is on . Iam sure there are lots of people who do such hacks and better ones than mine :-) ,as much as it is fun making them i would suggest taking them to a bigger audience and build a even more robust app is exciting and challenging . The team at plusmo respects such ideas and hackers would love to work with them and same with me ,if you are in india and have some really cool ideas with proven skills with technologies (mobile html ,python,popular socialnetwork API’s ,linux and opensource ) then please feel free to mail me up ,i would be more than happy to get you in touch with some people who can help you out .

Also to tell my friends ,yes iam very excited to be working with a team that looks great on paper and does work thats as good and exciting .

more to come so keep watching …..:-)

If you have an internet enabled phone ,then do check out their page to create your own widget or use their existsing ones or mobilize your blog with a button :-)

http://plusmo.com/create/publish.shtml

Send post as PDF to www.pdf24.org
6
Posted on 2nd December 2007 by Taggy

i was planning to put this one last week when i released meninblue but thanks to exam i just got time now .

It was basically a bot that would give you the latest commentary of india’s cricket matches on your twitter and it was written in python and using python-twitter .

First the libraries you will need

GNU/Linux or its variants preferred, python,urllib,urllib2,python-twitter and sgmlib and also minidom for xml parsing .

Twitter provides you with a very easy api to work with .posting a message is just two lines.

Here is how i have tried to go about my task .

Choose the main page where you get the list of all ongoing matches and i chose wap version of cricinfo since its easier to parse with minimal html and also their html is a little complex to parse with so many iframes .

i use the sgmllib to parse the html ,the code snippet is below

def get_contents(url):
import urllib, sgmllib


f=urllib.urlopen(”http://ci.plusmo.com/cricket/wap”)
s = f.read()
print “Read”
myparser = MyParser()
myparser.parse(s)
a=myparser.get_hyperlinks()
b=myparser.get_descriptions()
wget_command = “wget -p –output-document=index.html “+url
system(wget_command);
print wget_command
f=open(”$CWD/index.html”) #change the $CWD to what dir u have
filer=f.read()
strnew= filer.replace(’ ‘,’ ‘)
strnew1=strnew.replace(’ ‘,”)
findex=strnew1.find(’<div class=”dat”>’)
findex1=strnew1.find(’</div>’,findex+1,UP_LIMIT)
newindex=strnew1.find(’</div>’,findex1+1,UP_LIMIT_1)
newindex2=strnew1.find(’</div>’,newindex+1,NEW_LIMIT)
finalmesg=strnew1[findex:newindex2]
s=Stripper()
s.feed(finalmesg)
score=s.gettext()
score=score.replace(’<’,”)
score=score.replace(’>’,”)
score=score.replace(’div’,”)
print score
print “SCRE OBTAINED”
check(score)

And now the parser class

class MyParser(sgmllib.SGMLParser):
def parse(self, s):
self.feed(s)
self.close()
def __init__(self, verbose=0):
sgmllib.SGMLParser.__init__(self, verbose)
self.hyperlinks = []
self.descriptions = []
self.inside_a_element = 0


def start_a(self, attributes):
for name, value in attributes:
if name == “href”:
self.hyperlinks.append(value)
self.inside_a_element = 1


def end_a(self):
self.inside_a_element = 0


def handle_data(self, data):
if self.inside_a_element:
self.descriptions.append(data)


def get_hyperlinks(self):
return self.hyperlinks

def get_descriptions(self):

for i in range(len(self.descriptions)):
str=self.descriptions[i]
if str.find(”India”) != -1:
index=i

return self.descriptions

The next stage is to strip all html and get the full content which we can post :-)


class Stripper(sgmllib.SGMLParser):
def __init__(self):
self.data = []
sgmllib.SGMLParser.__init__(self)
def unknown_starttag(self, tag, attrib):
self.data.append(” “)
def unknown_endtag(self, tag):
self.data.append(” “)
def handle_data(self, data):
self.data.append(data)
def gettext(self):
text = string.join(self.data, “”)
return string.join(string.split(text))

And see if the last posted message was the same as the message you have ,if yes then abort posting and wait for a update to be done ( mostly for script when its running while no match is on or after play)


def check(score):
settings={
“username”:”YOURUSERNAME”,
“statusdelimeter1″:”<p class=\”entry-title entry-content\”>”,
“statusdelimeter2″:”</p>”
}



url1=”http://twitter.com/”+settings["username"]
message=”"
print url1
statusdelimeter1=settings["statusdelimeter1"]
statusdelimeter2=settings["statusdelimeter2"]
try:
print “In to the message checkloop”
instream=urllib.urlopen(url1)
for line in instream:
if statusdelimeter1 in line:
message=line[
line.index(statusdelimeter1)+len(statusdelimeter1):line.index(statusdelimeter2)
]


print message
print score
if string.lower(message)==string.lower(score):


print “No change in Score ,May be break or match just got over”
else:
if len(score)>140:
print “LEN Greater than 140,so truncating”
newscore=”
newscore=score[:140]
print newscore
twitter(newscore)

else:
twitter(score)


except IOError, e:
raise “Could not connect.”

And finally when you have the message to be sent ,just use a few lines of twitter library and its done !

def twitter(score):



import sys,os,string
sys.path.append(’$CWD/twitter/’)
sys.path.append(’$CWDsimplejson/’)
import twitter
api=twitter.Api(username=’YOUR_USERNAME’,password=’YOURPASS’)
try:
status=api.PostUpdate(score)
print “POST SUCCESSFULL”
except IOError,e:
raise”Could not Post”

Thats all the code is about :-)

check out 2s birthday update bot :-)

UPDATE: The feed and scores were taken from Plusmo services .

Z Plusmo2 Icon

Send post as PDF to www.pdf24.org
6
Posted on 24th November 2007 by Taggy

Twitter was always fun and now iam starting to do some things with it .

Inspired from Myles ,but his work was in ruby and i dont know much of it and iam lot comfortable with python .

so here is how you can get all the cricket updates of india matches right on your mobile when you are out roaming or on your gtalk while the cricket sites are banned in office .

  • Login to your twitter account at http://twitter.com
  • go to http://twitter.com/meninblue and choose the follow option
  • or if you are logged in to your gmail,gtalk then give ” Follow meninbue” command and you should be receiving my updates
  • And yes if you want to have the scores on your mob ,then dont forget to give out the phone details in the account section :-)

And i must warn you ,this script runs every 2 min so incase you dont want to be spammed ,follow only when you are comfortable with it !

http://twitter.com/meninblue

and thanks to sp2hari for helping out with html parsing and 2s for telling me about XPATH ,i figured out html parsing is lot tougher than XPATH and would definitely recommend it more than html parsers !.

And yes ,dont be surprised if some posts are truncated ,twitter allows only 140 chars and so i had to truncate the commentary else, it wont get posted !

PS:the libraries used are twitter,urllib,urllib2,sgmlib and XPATH ,source code will be up here soon,or if u want it then mail me at theyaga@gmail.com. will mail u the code

UPDATE: The feed and scores were taken from Plusmo services .

Z Plusmo2 Icon

Send post as PDF to www.pdf24.org
0
Posted on 3rd November 2007 by Taggy

Yeah ! this sem which is just about winding up has been the best of all the sems.This is how a typical CS dept at NIT,Trichy goes .Every day 2 classes and 2 lab sessions a week and the rest … .But this time we have had atleast 40 classes per subject and networks crossed 50.I know classes are a pain but the best part of this sem was the projects.

The hallmark of any good college is in the projects end up doing .I remember cs guys at iit’s doing projects that are at the very heart of computers.Be it with operating system or networks,compilers .For most part we worked with the same algorithmic implementations and blah blah but this semester it was decided not to have any lab sessions for internals.It will only be a one project demo at the end and the topics were carefully chosen so that they were not implemented.

Wel compilers lab had to be the best where we spent time learning automata and compiler compiling tools ( lex and yacc) so much for these that we have been using lex for all kinds of parsing :-) .

The networks landed us in to implementing RFC’s ,for those who don’t know what an RFC is ,it stands for request for comments.Where you propose a standard/protocol and let people comment on them and if many agree it goes on to become standard.

They are great because since they are not implemented,you cannot steal them and hence you end up learning at the very heart of networking ( network layer and not application layer) .

I had RFC 4501 which talks about implementing a DNS URI .Its defining a resource retrieval protocol for dns information .Just like how http:// is a resource identifier and similary ftp:// and it also brings with it parameters type .

for eg :

dns://google.com?type=mx dns://google.com?type=A is a query and you should be able to get the mail exchange records and Address records of google.com .I know its not difficult accessing these informations but getting to write your own code for this is a huge learning curve definitely .

As usual i started off with python and first thing i had to do was parse the dns://string?type=s & class=in .

The default parser for URL parsing somehow doesnt work for dns:// although it works flawlessly for http,ftp and smtp .Even cheap hacks in to the library didnt work so you start with lex to parse your input string and then find the type and schema to do the rest .

Doing this was a lot of fun as it was pretty much for the first time that i got to work on the networking basics,really .

And with Hari it was even more fun.His was RFC 4952 .It was to implement internationalized mail . for eg,

say i could type <ramesh in tamil font>@server.com and it should be sent to ramesh@server.com .This is fun isnt it ? he got to work with mail system in unix and also sendmail .

I guess these are some of the advantages you get when you study in one of the top T schools in the country ( Atleast that was what people tell us every year) .

And not to forget the apple stall that happened in campus this sem :-)

It has really been a super duper sem this and hopefully we will have a better one next sem with only project to go .

And for the news ,i am sure you guys must have heard about Iyer’s ( Yeah the same 96lpa guy ) crack at ACM kanpur .It was a record ,no team except his have ever managed to solve entire problem set in an ACM match and also that it was never in this history that IITB ACM team was ever beaten on indian soil.Both these things happened and Iyer said ” Killall kills all”

The results can be seen here http://icpc.baylor.edu/icpc/regionals/ViewRegionalStandings.asp?ContestID=866

The code for dns uri implementation is ready but a little ugly really ,will put it up when i clean it up for final code submission and yeah ssk is planning to start a code repository :-) in lan

Send post as PDF to www.pdf24.org
18
Posted on 27th October 2007 by Taggy

SMS gateways allow for the sending and receiving of SMS messages to or from devices and used to provide SMS network connectivity to third parties.You will need a mobile phone (supported) and sms gateway software.

While there are many propreitory solutions ,we went looking for opensource and free software .Kannel and gnokii ended up as best choices.

gnokii works well with many models but simpler the phone better the performance .using symbian phones only adds to complication. Although it supports varierty of protocols like bluetooth,infrared,serial .

We chose nokia 3100 and dku5 cable for the setup .

download the gnokii from its official download site

$ tar zxvf filename.tar.gz && cd gnokiii-xx

$./configure ( this shud tell you if you need to install any dependencies )

$ make && make install ( will finally install ,remember this command will have to be run as root )

now we need to create a config file .a sample file is given in /etc/gnokii/gnokiirc ,copy that file to ~/.gnokiirc

$cp /etc/gnokii/gnokiirc ~/.gnokiirc

now start editing your gnokiirc

sample config file for nokia3100 with dku5 cable is

First find out the port at which the cable is connected ,

$dmesg should tell you ,you must be seeing like /dev/ttyUSB0 most common .

port = /dev/ttyUSB0
model = 6510
connection = dku5

if this doesnt work then you will have to look at dmesg output to see if u see the dlr3p kernel drivier in output .in that case

 port = /dev/ttyUSB0
 model = 6510
connection = dlr3p

and now you we are all ready to get running .

$gnokii –identify

it should probe and give out the correct details of your mobile .its manufacturer ,model number version OS etc .

then lets try commands.

$gnokii –getsms IN 1 ( should get the latest sms in inbox )

$gnokii –sendsms 98xxxxx should send an sms to that number

$gnokii –help will tell you all the commands available.I tried calling from my gnokii and also attending calls from gnokii .

Now you can couple this with sms to have a complete daemon .smsd uses mysql so rest assured of all the sms sent .

Having said this ,i can tell you .Its not easy we have spent nights trying to get this .It will need a lot of your hacking skills to get anything :-) so happy hacking ! and yeah

#gnokii irc.freenode.net will help u

And why opensource sms solution ? because all the providers charge you nothing less than a lakh for setup .

Send post as PDF to www.pdf24.org

FireStats icon Powered by FireStats