Qondio
Front
Intel
IntelMart
Shares
My Qondio
Account
armen138 > Intel > How to make Ruby plurk

qondio.com/UJY4 PRINT EMAIL

How to make Ruby plurk

I’ve been on Plurk for a little while now, and I thought it would be cool to have a script that could plurk my latest activities from the commandline. So, I wrote this little Ruby script to do that :)

For the people who don’t know Plurk: Plurk is a social networking / micro-blogging site similar to twitter and the like.

The script is commented, so anyone with some knowledge of Ruby or even script languages in general should be able to make sense of it :)


#!/usr/bin/ruby

require ‘net/http’
require ‘uri’

#not sure if plurk cares about what browser you’re using, but just in case…
USERAGENT = ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1′

class Plurk
def initialize(usr, pswd)
#set these on the Plurk.new(…) line near the bottom
@username = usr
@password = pswd

#initiate connection to plurk
@http = Net::HTTP.new(‘www.plurk.com’, 80)

#this should be you
path = ‘/user/’+ @username

#these get filled by login
@cookie = “”
@userid = “”
#log in on plurk…
login()
end

def getUserID()
#your user id is hidden in the plurk sourcecode, we’ll grab it with a handy regular expression
path = ‘/user/’+ @username
resp, data = @http.get2(path, {‘User-Agent’ => USERAGENT, ‘Cookie’ => @cookie})
if(data =~ /“user_id”:\s(\d*?)\D/)
return $1
else
puts ‘no user id found’
end
return nil
end

def login()
#well, here we go then. logging in!
path = ‘/Users/login’
args = ‘nick_name=’ + @username +‘&password=’ + @password
headers = {
‘User-Agent’ => USERAGENT,
‘Referer’ => ‘http://www.plurk.com/user/’+@username,
‘Content-Type’ => ‘application/x-www-form-urlencoded’
}

resp, data = @http.post2(path, args, headers)
#on a successful login, plurk gives you a cookie as a reward. yum!
if(resp.response['set-cookie'] != nil)
@cookie = resp.response['set-cookie']
#now that we know login went alright, get the user id
@userid = getUserID()
if(@userid == nil)
@userid = “”
end
return true
else
puts ‘login failed!’
return false
end
end

def plurkThis(plurkstring)
#if getting the user id earlier failed, continuing here is useless.
#check login info, and pray plurk didnt break this in an update ;)
if(@userid == “”)
puts ’something went wrong, missing user id’
return
end
#we’ll have a look if the first word in your new plurk is one of plurk’s ‘qualifiers’
qualifiers = ‘ asks feels gives has hates hopes is likes loves needs says shares thinks wants was will wishes wonders ‘
words = plurkstring.split(/ /);
if(qualifiers =~ /#{words[0]}/)
qualifier = words[0]
content = plurkstring[words[0].size() + 1, plurkstring.size()]
else
qualifier = “:”
content = plurkstring
end
#this is all the stuff plurk needs to know to plurk your plurk.
args = ‘language=en&user_id=’ + @userid + ‘&qualifier=’ + qualifier + ‘&content=’ + URI.escape(content)
#plurk’s plurking-form is buried so deep in scripts, it is hard to figure out what goes where.
#fortunately, plurk’s mobile page is a lot simpler, and offers a straight-forward form to plurk with
path = ‘/m/’
headers = {
‘Cookie’ => @cookie,
‘User-Agent’ => USERAGENT,
‘Referer’ => ‘http://www.plurk.com/user/’+@username,
‘Content-Type’ => ‘application/x-www-form-urlencoded’
}
resp, data = @http.post2(path, args, headers)
#just letting you know your plurk has been plurked.
#if you don’t want the confirmation, just comment out the following line
puts ‘plurked: ‘ + @username + ‘ ‘ + qualifier + ‘ ‘ + content

end
end
#set your plurk username and password on the following line
plurk = Plurk.new(‘plurkNick’, ‘plurkPass’)
#this takes all commandline arguments, glues them into a single string, and plurks it :)
plurk.plurkThis($*.join(‘ ‘))

see http://nemra.nl for a more readable (indented, syntax-highlighted) version! :)


Contributor's Note

Blog post contains colored, indented syntax-highlighted code for better readability.

External Links

Plurk

Contributed by armen138 on August 24, 2008, at 00:30 AM UTC.

Reactions

No reactions yet.

Rate This Intel

Please login or sign up to rate this intel.

Comments

Please login or sign up to add a comment.

Share

Copyright Notice

The copyright for this content entitled "How to make Ruby plurk" has been specified by the contributor as:

All Rights Reserved

This content may not be copied, distributed or adapted by anyone under any circumstances.

Login Here with
Any Email Address
Any Password
No account? Sign up.

Intel Contributor
This intel was contributed by armen138

Qondio Archive
May, 2012
123456
78910111213
14151617181920
21222324252627
28293031


2008
January, February, March, April, May, June, July, August, September, October, November, December
2009
January, February, March, April, May, June, July, August, September, October, November, December
2010
January, February, March, April, May, June, July, August, September, October, November, December
2011
January, February, March, April, May, June, July, August, September, October, November, December
2012
January, February, March, April, May

Sign Up
Not a member yet? Qondio is a powerful network for making it online. If you have a website to promote, we can help. Sign up and get in on the action.

About Qondio
Welcome to Qondio! Discover the awesome power this network can deliver by going to our About page. Or you could skip straight to the Sign Up form.

ABOUT
SUCCESS GUIDE
FEATURES
FAQ
ADVERTISE
CONTACT
USAGE POLICY
PRIVACY POLICY


TWITTER
FACEBOOK