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 .
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 !
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 .
The tussle between Google yahoo and Microsoft for their space on their internet took a new turn with live maps becoming so much better (yeah even better than the google i will say ) .
Directions was something that did come in Google long ago ,Yahoo added to its yahoo maps recently but of all these i find Live Maps most attractive (UI and its tips ) ,the color changes from old live maps have been explained and also what comes as surprise is the traffic parameter that has been taken in calculation the shortest_distance/shortest_path .
Whats added is also simultaneous search by business and people ( didn’t try anything though ) yahoo maps comes closest to these features but microsoft with its huge bag full of money and intention to make its space in the internet we could see some serious competition .
Silverlight platform for RIA looks great from microsoft too ,name tafiti it shows the power of silverlight. And we all know of microsofts interest in facebook ( evaluating it for close to $16bn ,i doubt if anything comes even anything closer to facebook apart from myspace .even orkut has less traffic from us ) .
Yahoo has its Mash beta ,but its a bit too early for anyone to get addicted to it ,i find very little reasons to login to it .And even strange is havig a pet and do some actions on it ( feed it,kill it ).But yes the prospect of what might be still coming is worth waiting .At the moment i think facebook is really really nice,not letting strangers get anywhere close to you unlike in orkut where anyone can scrap you and it has become full of spammers ! .
hopefully mash will be lot better than Orkut ! :-)
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 .
I loved GS on MT ,it lets me do many things that i do only on my laptop but with a gift ready i think i would love to move on to dedicated virtual server on MT .its a little costly though $50 a month :( .
Any coupons that will help me bring it to under $40 ? . i know kirupa05 gives you a 15 % discount but still,may be upgrade from gs to mt costs less ?
Iam looking for some nice discount coupons ,anyone ?
and yeah MT is coming up with Django on grid servers ! i have applied for the beta programe ,still waiting ?
[tags]mediatemple,vps,dv,hosting [/tags]


Iam Theyagarajan S ( 'taggy') . to know more ,head out to



