I have written a working ruby script using mechanize for fetching my
- Stackoverflow reputation and badges
- Twitter tweets and followers
and printing the output to screen.
I run this command on the terminal first :
/Users/cyclotrojan/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /Users/cyclotrojan/Desktop/Snippets/get_so_reputation_and_tw_followers.rb
The output is correctly displayed like this on the terminal:
StackOverflow :
Reputation is : 406
Total Badges : 10
Twitter :
Tweets : 1,494
Followers : 137
Now I wish to display the output of my script on my desktop using GeekTools and set refresh time to 30 minutes, so it keeps running the script over and over thus updating my stats. However when I paste the same command on a geektool shell, no output comes.
Here is the script :
File get_so_reputation_and_tw_followers.rb
require 'mechanize'
def get_stackoverflow_data
url_so = 'https://stackoverflow.com/users/898346/cyclotrojan'
begin
so_page = Mechanize.new.get(url_so)
so_reputation = so_page.link_with(:href => "/users/898346/cyclotrojan?tab=reputation").to_s
so_badges = so_page.search(".badgecount").first
print "StackOverflow :" + "\n"
print " Reputation is : " + so_reputation + "\n"
print " Total Badges : " + so_badges + "\n"
rescue
print "StackOverflow :" + "\n"
print "\tReputation is : " + "NA" + "\n"
print "\tTotal Badges : " + "NA" + "\n"
end
end
def get_twitter_data
url_tw = 'https://twitter.com/cyclotrojan'
begin
tw_page = Mechanize.new.get(url_tw)
tw_tweets = tw_page.link_with( :href => "/" + url_tw.split("/").last).to_s.split(" ").first
tw_followers = tw_page.link_with( :href => "/#!/" + url_tw.split("/").last + "/followers").to_s.split(" ").first
print "Twitter :" + "\n"
print "\tTweets : " + tw_tweets + "\n"
print "\tFollowers : " + tw_followers + "\n"
rescue
print "Twitter :" + "\n"
print "\tTweets : " + "NA" + "\n"
print "\tFollowers : " + "NA" + "\n"
end
end # end function
get_stackoverflow_data()
get_twitter_data()
However, the output simply doesnt show up on my desktop. I know that the problem is not with detecting ruby, since I tested it out using another file test.rb
File test.rb
puts "hello"
This command will work on GeekTool shell and display hello correctly :
/Users/cyclotrojan/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /Users/cyclotrojan/Desktop/Snippets/test.rb;
Output on geektool shell: hello
I have done some debugging and found that if I remove the line require 'mechanize' then the script runs correctly and due to exception the following output is displayed :
StackOverflow :
Reputation is : NA
Total Badges : NA
Twitter :
Tweets : NA
Followers : NA
So the issue is with including mechanize in the script. Please help me in resolving this. Thnx !
These questions didnt help : How to run Ruby scripts in Geektool? , Ruby, Mac, Geektool question, file access rights?
You would be able to tell if you didn't try to rescue the error. It looks like our old friend ssl verify error so try this:
I should add that you might want to make sure you understand the consequences of OpenSSL::SSL::VERIFY_NONE
Also here is a tip: