Posts tagged ‘google’

Use Google Docs for generating live reports on your Ruby scripts

I have to transfer and convert a lot of files this week, and in order not to loose track, I created a spreadsheet that summarizes which files are transferred and converted. Because it was a pain to keep the spreadsheet up to date I wrote a Ruby script that monitors the files written and writes the results back to a Google docs spreadsheet.

To monitor the files I use the so-called backtick quote, which reads the output of a command to a variable:

res = `cd /home/thefolder;ls -l`
res.each_line do |line|
  cols = line.split(' ')
  if cols.length<9  #probably a header row
    next
  end
  if File.file?('/home/thefolder/'+cols[8])
    #the file exists, your code here
    #my code writes to a hash called items
  end
end
To write the results back I used gimite’s google-spreadsheet-ruby gem (http://github.com/gimite/google-spreadsheet-ruby) that makes it trivially easy to connect to a Google spreadsheet (just follow the “how to use” on the first page).
def dump_to_google(items)
  session = GoogleSpreadsheet.login("user@gmail.com", password)
  ws = session.spreadsheet_by_key("YOURKEYYOURKEYYOURKEY").worksheets[0]
  col = 1 
  row = 1
  ws[row,1] = 'ID'
  ws[row,2] = 'Filename'
  ...
  row+=1
  items.each do |id,itm|
    ws[row,1] = id
    ws[row,2] = itm[:filename]

     ...
    row+=1
  end
  ws.save()
end

The end result is pretty cool, a spreadsheet that is updated every minute (or whatever interval you decide). You can also create graphs that are updated automatically with the new data:




Advertisements

December 10, 2009 at 9:13 pm Leave a comment

At last! Streetview in Belgium

Seems like Google Street View is coming to Belgium! Cities like Ghent, Brussels and Antwerp will be covered by street view according to news bulletins. But I knew it before that because this weekend we chased the Google Streetview car here in Ghent with our bikes 🙂

March 16, 2009 at 7:12 pm Leave a comment


Feeds

Articles to be written…

Twitter – kr3l

my del.icio.us

RSS Google Reader Shared Stuff

  • An error has occurred; the feed is probably down. Try again later.

RSS Listening to..

  • An error has occurred; the feed is probably down. Try again later.