Skip to content

Instantly share code, notes, and snippets.

@stevensona
Created September 17, 2016 16:20
Show Gist options
  • Save stevensona/c4de78b16ad44916075e7948602a2cc6 to your computer and use it in GitHub Desktop.
Save stevensona/c4de78b16ad44916075e7948602a2cc6 to your computer and use it in GitHub Desktop.
execute ruby script with cron job (rbenv)
SHELL=/bin/bash
0 * * * * /bin/bash -c 'export PATH="$HOME/.rbenv/bin:$PATH" ; eval "$(rbenv init -)"; cd $HOME; ./script.sh >> $HOME/jobs.log 2>&1'
@thepoho
Copy link

thepoho commented Apr 8, 2020

#!/usr/bin/env ruby
require 'mechanize'

RESOURCES = [
  {
    name: 'Low Temperature Diamonds',
    url:  'https://eddb.io/commodity/276'
  },
  {
    name: 'Void Opals',
    url:  'https://eddb.io/commodity/350'
  },
]

CSV_FILE = '/data/eddb.csv'

a = Mechanize.new
output = [Time.now.iso8601]
RESOURCES.each do |resource|
  page = a.get(resource[:url])
  value = page.search('div.overview-value.number')[2].children.first.text
  value = value.gsub(' Cr','')
  value = value.gsub(',','')
  output << value
end

File.open(CSV_FILE,'a'){|f| f.puts(output.join(','))}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment