Mashing Twitter and FSO
by sudharsh
I really love Twitter and it didn’t make any sense to me to shell out a rupee for every tweet sent through my Airtel Mobile. Moreover, I am on one of those monthly booster packs which allows you to send 22000 text messages for free. I simply had to exploit this by setting up my own little ‘OC’ twitter forwarder written in python. (I know of smstweet.in service but I am still charged 1.50 for every tweet I send)
Its insanely simple to write such a ‘forwarder’ in python using the services provided by the FSO (freesmartphone.org) Framework,
- Send messages to your old/unused number whose SIM is in the Freerunner (or any other device supported by the FSO framework)
- Handle the incoming messages and use python-twitter API (or) raw urllib2 to post updates. Of course, the device should be connected to the internet, you can tether this device to an old unused computer. Simply put, the Freerunner should be able to access the internet.
I know this is dumb given cheap GPRS and all, but what the heck; Sundays _are_ reserved for dumb things and I wanted to show off how easy it is to develop and conjure up simple but powerful scripts using open hackable hardware like the Freerunner. So take off your pedantic hats
Here is the actual python code,
#!/usr/bin/env python
# Written By Sudharshan S, http://sudharsh.wordpress.com
import dbus
import time
import logging
import twitter
import gobject
from gobject import MainLoop
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop (set_as_default = True)
# Use OAUTH?
USERNAME = "username"
PASSWORD = "password"
log = logging.getLogger("TweetForwarder")
class TweetForwarder:
"""Process Incoming messages and update twitter status
if the message startswith 'tweet'
"""
def __init__(self, username, password):
log.warning("Starting up....")
self.twitter_api = twitter.Api(username=username, password=password)
# Get proxies and add signal handlers
bus = dbus.SystemBus()
_usage = bus.get_object("org.freesmartphone.ousaged",
"/org/freesmartphone/Usage")
_proxy = bus.get_object("org.freesmartphone.ogsmd", \
"/org/freesmartphone/GSM/Device")
self.usage_iface = dbus.Interface(_usage, "org.freesmartphone.Usage")
self.usage_iface.RequestResource('GSM')
self.sms_iface = dbus.Interface (_proxy, "org.freesmartphone.GSM.SMS")
self.sms_iface.connect_to_signal ("IncomingMessage", self.onIncomingMessage)
def onIncomingMessage(self, sender, message, kwargs):
log.warning("Received SMS from %s:%s" % (sender, message))
# We don't ALL messages to this number to be tweeted
if message.strip().startswith("tweet "):
log.warning("Trying to update status : %s" % message[6:].strip())
self.twitter_api.PostUpdate(message[6:])
log.warning("Updated Status")
def run(self):
loop = MainLoop()
loop.run()
if __name__ == "__main__":
logging.basicConfig()
server = TweetForwarder(USERNAME, PASSWORD)
server.run()
Make sure you have python-netclient and python-json installed on your Freerunner. These can be installed using the ‘opkg install’ command.
The script and the accompanying dependency can be downloaded from here. Just change the USERNAME and PASSWORD accordingly after scp’ing the tarball to your device.
Some useful links,
[2]: DBus Tutorial
Hi,
http://en.support.wordpress.com/code/posting-source-code/
see this link and beautify your code in wordpress blog.
sir, engayo poiteenga… Just what I was looking for. Thanks!
Nice hack. Any idea how to get and how much does a freerunner cost in India? I can google, but if you have information won’t mind a first hand account of it.
Infact if you have a free sms package from your operator, http://www.smstweet.in will also not cost you 1.5/- national sms.
Hi, Thanks! I got my device for free as part of my GSoC project last year
.
IDA systems are the distributors in India, but that said there are a lot of second hand freerunners floating in the internet.
There is also the community powered gta02-core project, which will make for an awesome hackable hardware
http://gta02-core-news.blogspot.com/
http://wiki.openmoko.org/wiki/Gta02-core
This will be especially interesting since you can setup a ‘smstweet.in’ clone rather easily
Thanks for the info sudharsh. Will check it out
>This will be especially interesting since you can setup a ’smstweet.in’ clone rather easily
Why should I clone smstweet.in? I run smstweet.in
. Moreover you cannot run an application of the scale of smstweet on a physical phone receiving 100′s of smses.
@excogito
> Why should I clone smstweet.in? I run smstweet.in
.
Whoops…
, didn’t know that
> Moreover you cannot run an application of the scale of smstweet > on a physical phone receiving 100’s of smses.
Yep. Agreed.
I’ve code that can set up a ‘twitter forwarder’ in both directions (replies and tweets), and runs on any phone (uses python-gammu to interface with phones using AT commands).
I’ll move it from my private hg to public git soon, but if you want a look, hig me up
sure post the url here… One of the folks at office, wanted to use gammu as well. But we never got a chance to use it (call it laziness
)
He can send a sms and gets the price through sms. if the customer finds out that in online store price is cheap..he will not buy frm physical store…i.e extending the search feature to mobile by use of an application.