Sha256: e122d4e7ba642ab173cdfb4c35b05581b581dac6cb9b6ae0bbe70b069fe7db29

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

#!/usr/bin/env ruby

require 'fileutils'
require 'slop'
require 'neatjson'
require 'clock_window'

opts = Slop.parse do |o|
  o.banner = <<-BANNER
Clock Window - "Clock your desktop activity!"
Copyright (c) 2016 Daniel P. Clark via the MIT License
Version: #{ClockWindow::VERSION}

usage: clock_window [options]
BANNER
  o.bool "-c", "--clean", "Use all known name filters"
  o.string "-o", "--output", "File/directory output in strftime"
  o.bool "-e", "--eager", "Use strftime of time at start of script\n"

  o.on "--version", "Print the version" do
    puts ClockWindow::VERSION
    exit
  end
  o.bool "-h", "--help", "This help menu\n\n"
end

if opts[:help]
  puts opts
  exit
else
  puts opts.to_s.partition("\n\n").first
  puts "\nPress CTRL-C to exit the script."
  puts "Starting active window tracking!"
end 

dir_name, _, file_name = opts[:output].to_s.rpartition(File::SEPARATOR)
file_name = "timelog.json" if file_name.empty?

@time = Time.now if opts[:eager]
@hash = {}
begin
  loop do
    filter_opts = opts.clean? ? {filter_opts: {no_notify: true}} : {}
    x = ClockWindow::ClockIt.new(**filter_opts).active_window
    @hash[x] = @hash[x].to_f + 0.25
    sleep 15
  end
ensure
  @hash = {"*---------- WINDOW NAME ----------*" => "minutes"}.merge(@hash)
  @time ||= Time.now
  dir = @time.strftime(dir_name)
  FileUtils.mkdir_p(dir) unless dir.empty?
  file = @time.strftime(file_name)
  File.open("#{dir}#{File::SEPARATOR unless dir.empty?}#{file}","w") do |f|
    f.write(JSON.neat_generate(@hash,aligned:true,around_colon:1))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clock_window-0.0.6 exe/clock_window