Sha256: e6d1200c5d9de34a118090c222c695509aec79f45f3664d25fee2cc70a6f9147

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

#!/usr/bin/env ruby

require 'insulin'
require 'thor'

module Insulin
  class I < Thor
    @@mongo = Insulin::MongoHandle.new ({"database" => "insulin"})

    desc "ingest FILE",
      "ingest OnTrack CSV export FILE"
    def ingest file
      csv = Insulin::OnTrack::CsvFile.new file
      csv.save_events @@mongo
    end

    desc "day DATE",
      "show stats for day DATE (default is today)"
    def day date = nil
      if not date
        require 'time'
        date = Time.new.strftime "%F"
      end
      begin
        d = Insulin::Day.new date, @@mongo
        puts d
      rescue NoMethodError
        puts "No data for %s" % date
      end
    end

    desc "week DATE",
      "show stats for week commencing DATE (defaults to previous 7 days)"
    def week date = nil
      if not date
        require 'time'
        date = (Time.new - (7 * 86400)).strftime "%F"
      end
      w = Insulin::Week.new date, @@mongo
      puts w.to_s
    end

    desc "month DATE",
      "show stats for 30-day period commencing DATE (defaults to previous 30 days)"
    def month date = nil
      if not date
        require 'time'
        date = (Time.new - (30 * 86400)).strftime "%F"
      end
      m = Insulin::Month.new date, @@mongo
      puts m.to_s
    end

    desc "pdf RECIPIENT",
      "generate a PDF for the last week and mail to RECIPIENT"
    def pdf recipient = nil
      date = (Time.new - (7 * 86400)).strftime "%F"
      outfile = "/tmp/insulin.pdf"
      p = Insulin::Pdf.new Insulin::Week.new(date, @@mongo), outfile
      p.render

      require 'pony'
      Pony.mail(
        :to => recipient,
        :from => "insulin@cruft.co",
        :subject => "insulin report",
        :body => "Attached",
        :attachments => {
          "insulin.pdf" => File.read(outfile)
        },
        :charset => 'utf-8'
      )
    end
  end
end

Insulin::I.start

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
insulin-0.1.10 bin/insulin
insulin-0.1.9 bin/insulin