3

The script is in the file fxrates_scraper.rb, code below.

The scheduler i'm using is in the schedule.rb file, code below.

I'm using the whenever gem, and when i type in 'bundle exec whenever' i see the task as scheduled, it seems fine. but it doesn't work: it isn't executing the script.

what am I doing wrong? note i haven't setup capistrano or anything, i just want the script to run on my local drive. also: when i execute the script manually, it runs just fine. it's just the automation bit that isn't working.

FXRATES_SCRAPER.RB

 require 'open-uri'
    require 'nokogiri'
    require 'csv'

# Store URL to be scraped
url = "https://deliveroo.co.uk/restaurants/london/maida-vale?postcode=W92DE"

# Parse the page with Nokogiri
page = Nokogiri::HTML(open(url))

# Display output onto the screen
name =[]
page.css('span.list-item-title.restaurant-name').each do |line|
  name << line.text.strip
end

category = []
page.css('span.restaurant-detail.detail-cat').each do |line|
  category << line.text.strip
end

delivery_time = []
page.css('span.restaurant-detail.detail-time').each do |line|
  delivery_time << line.text.strip
end

distance = []
page.css('span.restaurant-detail.detail-distance').each do |line|
  distance << line.text.strip
end

status = []
page.css('li.restaurant--details').each do |line|
  if line.attr("class").include? "unavailable"
    sts = "closed"
  else
    sts = "open"
  end
  status << sts
end

# Write data to CSV file
CSV.open("deliveroo.csv", "w") do |file|
file << ["Name", "Category", "Delivery Time", "Distance", "Status"]
  name.length.times do |i|
      file << [name[i], category[i], delivery_time[i], distance[i], status[i]]
  end
end

SCHEDULE.RB

set :output, "#{path}/log/cron.log"
every 2.minutes do
  command "ruby '#{path}/fxrates_scraper.rb'"
end

OUTPUT FROM RUNNING 'BUNDLE EXEC WHENEVER' COMMAND

 Faisals-Air:whatrate fkhalid2008$ bundle exec whenever
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'ruby '\''/Users/fkhalid2008/whatrate/fxrates_scraper.rb'\'' >> /Users/fkhalid2008/whatrate/log/cron.log 2>&1'

## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
hikmatyar
  • 265
  • 3
  • 14

2 Answers2

0

Running 'whenever -i' command fixed this.

hikmatyar
  • 265
  • 3
  • 14
0

IMO, you have to set environment when run whenever:

bundle exec whenever --update-crontab --set environment='development'
Vincent Nguyen
  • 311
  • 3
  • 5