Class: Timelapse::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/timelapse.rb

Instance Method Summary collapse

Instance Method Details

#start(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/timelapse.rb', line 10

def start(options={})
  begin
    options[:interval] = "30s" unless options.has_key?(:interval)
    save_options = {:to_folder => options[:output]} if options.has_key?(:output)
    puts "Connecting to camera..."
    camera = GPhoto2::Camera.new
    puts "Using #{camera.model_name}"
    puts "Interval: #{options[:interval]}"
    puts "Output: #{options[:output]}" if options[:output]
    scheduler = Rufus::Scheduler.start_new
    scheduler.every options[:interval] do
      puts "Taking picture..."
      camera.capture.save(save_options).delete
      puts "Saved to disk."
      filename = "LICENSE.txt"
      puts options
      if options[:s3_bucket]
        s3 = AWS::S3::Base.establish_connection!(
          :access_key_id     => options[:s3_access_key], 
          :secret_access_key => options[:s3_secret_key]
        )
        AWS::S3::Bucket.create(options[:s3_bucket])
        AWS::S3::S3Object.store(filename, open(filename), options[:s3_bucket])

        puts "Uploaded to S3."
      end

      if options[:ftp_server]
        ftp = Net::FTP.new(options[:ftp_server])
        ftp.(options[:ftp_user], options[:ftp_password])
        puts ftp.pwd()
        ftp.chdir(options[:ftp_path]) if options[:ftp_path]
        ftp.storbinary('STOR', filename, open(filename))
        ftp.close
        puts "Uploaded to FTP."
      end

    end
    scheduler.join
  rescue => e
    puts e
  ensure
    camera.dispose
  end
end