01110100110101010101011101100010
Posts tagged twitter
Get updates of completed torrents via SMS
Apr 6th
This Sunday when i was giving DBUS a look and thinking about all the cool things possible with it, one of my friend came asking how can he control his torrents from anywhere and i thought controlling is ok, do you want SMS updates??, i fired up qdbusviewer and there it was a simple way to get sms notifications of finished torrents using well twitter and ktorrent, so here are the steps
1) setup your cell phone to recieve SMS updates in twitter,
2) get one more twitter account lets say ktorrent, follow ktorrent and turn device updates on,
3) now save the script below say as torrenttwit.py
4) now enter this ktorrent account username and password in the script below,
5) start ktorrent if not already started, now run the script by typing “python torrenttwit.py”
import dbus,base64,urllib2,urllib
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
username="username"
password="password"
def tweet(msg):
request = urllib2.Request('http://twitter.com/statuses/update.json')
request.add_header('Authorization', 'Basic %s' % base64.encodestring('%s:%s' % (username,password))[:-1])
request.add_data(urllib.urlencode({'status': msg.encode('utf-8')}))
opener = urllib2.build_opener()
req= opener.open(request)
s = dbus.SessionBus()
kt = s.get_object("org.ktorrent.ktorrent","/core")
def update(k):
torrent = s.get_object("org.ktorrent.ktorrent","/torrent/"+k)
name = torrent.get_dbus_method("name","org.ktorrent.torrent")
tweet("ktorrent: finished " +name())
kt.connect_to_signal("finished",update)
import gobject
loop = gobject.MainLoop()
loop.run()
you are done, now whenever a torrent finishes the script will twit and you will receive an SMS update
enjoy
Twit from command line (Linux)
Dec 4th
Here is a thing that i found during searching for a completely different things, you can update your Twitter status simply by using curl which is most of the time installed by default so here is the command
/usr/bin/curl -u username:password -d status="your tweet" http://twitter.com/statuses/update.xml
it simply updates your twitter status, this is extremely simple and could easily be used to update status, but the problem is that it contains your password and you dont want to display your password so you can make a simple script for it which asks you for the tweet and displays if successful or not
#!/bin/sh
echo Post your tweet.......
read tweet
/usr/bin/curl -u <username>:<password> -d status="$tweet" http://twitter.com/statuses/update.xml
if [[ "$?" == 0 ]];
then
echo Updated successfuly!!!!
exit 0
else
echo Something went wrong try again!!!!
exit 1
fi
to make it just login as root by ‘sudo -i’ or ‘su’ and type gedit /usr/local/bin/twit now paste the script and replace <username> and <password> with username and password of your twitter account and save the file, we will change the permissions for the file and make it executable by typing chmod +x /usr/local/bin/twit all done now when you want to twit just type twit on command line and let the world know what you are doing.
PS:- if you are on twitter feel free to add me http://twitter.com/ankur



