made it work, more or less, with ruby 1.9
[nyuron.git] / calendar.rb
bloba9883b3689c1c25cc584391a0130ac8ec91f583b
1 #!/usr/bin/env ruby
2 #---------------------------------------
3 # This script generates a plain text overview
4 # of important notes for integration in other
5 # applications such as window managers.
7 require 'sqlite3'
8 require 'pathname'
9 $: << MYDIR = File.dirname(Pathname.new(__FILE__).realpath)
11 require 'modules/boot'
12 require 'modules/convert/time'
14 class Neuron
15         attr_reader :time
16         def initialize(row)
17                 @value, @time = row
18                 @time = Time.at(@time.to_i)
19         end
20         def <=>(other)
21                 @time <=> other.time
22         end
23         def to_s
24                 ts = Convert.time_to_string(@time).rjust(17)
25                 return "#{ts}: #@value"
26         end
27 end
29 fname = Boot.get_conf_path
30 dbfile = nil
31 load fname if fname
32 dbfile = Boot.get_database_path(dbfile)
34 abort 'no database found...' unless dbfile
37 $now = Time.now
38 db = SQLite3::Database.new(dbfile)
40 query = <<X
41 SELECT value, info1
42 FROM nyu
43 WHERE type='txt'
44 AND NOT info1=''
45 AND info1>#{$now.to_i}
46 AND tags GLOB '*/i/*'
47 ORDER BY info1
50 neurons = []
51 db.execute(query) do |row| neurons << Neuron.new(row) end
52 unless neurons.empty?
53         t = neurons.first.time
54         puts "Time left: #{Convert.relative_time_to_string(t)}"
55         neurons.each do |nyu| puts nyu end
56 end
58 puts
59 system 'cal'