Jump to content

Welcome the ORIGINAL FileMaker Community

Take a moment to join us, no noise, all FileMaker...We Promise

Sign in to follow this  
cwilliams10

Display New Posts on Desktop using GeekTool & Ruby

Recommended Posts

cwilliams10

For those of you who use GeekTool here is script that will display New Posts on your desktop. It uses Ruby and the RubyGem Mechanize. Mechanize is a very useful tool for webscraping, filling in forms, posting to blogs, etc.

 

What I like most about this approach is that I do not have to continually refresh a browser window to see the latest posts.

 

Requirements: Ruby, RubyGems, Mechanize, GeekTool

 

Here is what it looks like on my desktop:

FileMakerToday.jpg

 

Instructions:

Install Ruby, RubyGems and Mechanize if not already installed.

Save this script with a '.rb' extension.

In GeekTool create a new Shell entry: /usr/bin/ruby "/path/to/posts.rb" // Wherever you saved this file.

Set the repeat time to desired time but make it at least several minutes.

 

Script Variables You MUST change:

The only way to see New Posts is to be a member of FileMaker Today making login required.

USERNAME = 'YOUR_USERNAME'

PASSWORD = 'YOUR_PASSWORD'

 

Script Variable Optionally Change:

This is the number of posts you want displayed on your monitor.

POST_LIMIT = 5

 

The number of seconds between updates. This is for display only and should be set to the same value as what you set in GeekTool.

UPDATE_TIME = 300

 

require 'rubygems'
require 'mechanize'
require 'cgi'

agent = WWW::Mechanize.new

USERNAME = 'YOUR_USERNAME'
PASSWORD = 'YOUR_PASSWORD'
POST_LIMIT = 5
UPDATE_TIME = 300  # set this to same value in GeekTool 

# Login
page = agent.get('http://www.filemakertoday.com/com/index.php')
form = page.forms[1]
form.field('vb_login_username').value = USERNAME
form.field('vb_login_password').value = PASSWORD
page = agent.submit(form)

page = agent.get('http://www.filemakertoday.com/com/search.php?do=getnew')
html = page.body


links = html.grep(/id="thread_title/)
rep = html.grep(/Replies:/)
post_time = html.grep(/span class="time"/)
poster = html.grep(/href="member.php/)

time_now = Time.now
time_from_now = time_now + UPDATE_TIME

listing = "----------------------------------------\n" 
listing += "#{time_now}\n"
listing += "Next update at: #{time_from_now.strftime("%H:%M:%S")
}\n"
listing += "----------------------------------------\n"

links.each_with_index do |link, i|
   break if i == POST_LIMIT
   views = rep[i].scan(/title="(.+)">/)[0][0]
   title = link.scan(/.+>(.+)<\/a>/)[0][0]
   time = post_time[i].scan(/<span class="time">(.+)<\/span>/)[0][0]
   name = poster[i].split("<a")[1].scan(/rel=".+">(.+)<\/a>/)[0][0]
   listing << "#{CGI.unescapeHTML(title)}\n#{views}\nLast post at #{time} by #{name}\n\n"
end

puts listing

Share this post


Link to post
Share on other sites
This thread is quite old. Please start a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use