thartmx 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "thartmx"
8
+ gem.summary = %Q{rtmapi based remember the milk cli.}
9
+ gem.description = %Q{rtmapi fixed version with a simple cli added, rtmapi package fixed to work with libxml2 version > 2.7}
10
+ gem.email = "thamayor@gmail.com"
11
+ gem.homepage = "http://github.com/ghedamat/thartm"
12
+ gem.authors = ["tha"]
13
+ #gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", ]
15
+ gem.add_dependency 'tzinfo'
16
+ gem.add_dependency 'libxml-ruby'
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.libs << 'lib' << 'test'
28
+ test.pattern = 'test/**/test_*.rb'
29
+ test.verbose = true
30
+ end
31
+
32
+ begin
33
+ require 'rcov/rcovtask'
34
+ Rcov::RcovTask.new do |test|
35
+ test.libs << 'test'
36
+ test.pattern = 'test/**/test_*.rb'
37
+ test.verbose = true
38
+ end
39
+ rescue LoadError
40
+ task :rcov do
41
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
42
+ end
43
+ end
44
+
45
+ task :test => :check_dependencies
46
+
47
+ task :default => :test
48
+
49
+ require 'rake/rdoctask'
50
+ Rake::RDocTask.new do |rdoc|
51
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "thartmx #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.9
data/bin/rrtm ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../lib/thartm.rb'
3
+
4
+ CONFIGFILE = File.join(File.expand_path(ENV['HOME']), '.rtm')
5
+ begin
6
+ @@config = YAML.load_file(CONFIGFILE)
7
+ rescue
8
+ raise "please create a .rtm file in your $HOME"
9
+ end
10
+
11
+
12
+ #ENV['TZ'] = @@config['tz']
13
+
14
+ # validating token
15
+ unless @@config['token']
16
+ @rtm = ThaRememberTheMilk.new(@@config['key'],@@config['secret'])
17
+ puts "please authorize this program: open the following url and puts the frob value back here."
18
+ puts @rtm.auth_url
19
+ frob = gets
20
+
21
+ auth = @rtm.auth.getToken('frob' => frob.chomp)
22
+ token_file = File.open(CONFIGFILE,"+w")
23
+ token_file << "token: " + auth.token
24
+
25
+ puts "restart the program now"
26
+ exit
27
+ end
28
+
29
+
30
+ cli = CommandLineInterface.new(@@config['key'],@@config['secret'],@@config['token'])
31
+ if ARGV[0]
32
+ begin
33
+ cli.send ARGV[0]
34
+ rescue Exception => e
35
+ puts e, "command #{ARGV[0]} is not available"
36
+ cli.help
37
+ end
38
+ else
39
+ cli.tasks
40
+ end
data/lib/thartmx.rb ADDED
@@ -0,0 +1,268 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'yaml'
5
+ require 'tzinfo'
6
+ require File.dirname(__FILE__) + '/thartmx_lib.rb'
7
+
8
+ class Rrtm
9
+
10
+ def initialize(key,secret,token)
11
+ #@rtm = ThaRememberTheMilk.new(@@config['key'],@@config['secret'],@@config['token'])
12
+ @rtm = ThaRememberTheMilk.new(key,secret,token)
13
+ @rtm.use_user_tz = true
14
+ @rtm.debug = false
15
+
16
+ # id of the all tasks list
17
+ @allTaskList = String.new
18
+
19
+ @lists = lists
20
+ @timeline = @rtm.timelines.create
21
+ end
22
+
23
+ def allTaskList
24
+ allTaskList = ''
25
+ @lists.each do |k,v|
26
+ if v[:name] == "All Tasks"
27
+ allTaskList = v[:id]
28
+ end
29
+ end
30
+ return allTaskList
31
+ end
32
+
33
+ def findList(name)
34
+ flist = ''
35
+ name.chomp!
36
+ @lists.each do |k,v|
37
+ if v[:name] == name
38
+ flist = v[:id]
39
+ end
40
+ end
41
+ return flist
42
+ end
43
+ def lists
44
+ lists = @rtm.lists.getList
45
+ end
46
+
47
+ def tasks(args = {})
48
+ tasks = @rtm.tasks.getList args
49
+
50
+ end
51
+
52
+ def tasksAllTaskList
53
+ t = tasks :list_id => allTaskList
54
+ end
55
+
56
+
57
+ def addTask(name)
58
+ if name =~ /^(@(\w|\s)+@)/
59
+ listname = name.match(/^(@(\w|\s)+@)/)[0][1..-2]
60
+ name.sub!(/^(@(\w|\s)+@)/,'')
61
+ end
62
+ listid = allTaskList
63
+ if listname
64
+ @lists.each do |k,v|
65
+ if v[:name].match(listname)
66
+ listid = v[:id]
67
+ end
68
+ end
69
+ end
70
+
71
+ @rtm.tasks.add :timeline => @timeline, :name => name, :parse => '1', :list_id => listid
72
+ end
73
+
74
+ def findTask(id)
75
+ tt = tasks
76
+ tt.each do |key,val|
77
+ val.each do |k,v|
78
+ return v if v[:id] == id
79
+ end
80
+ end
81
+ return nil
82
+ end
83
+
84
+ def completeTask(id)
85
+ v = findTask(id)
86
+ @rtm.tasks.complete :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id
87
+ end
88
+
89
+ def postponeTask(id)
90
+ v = findTask(id)
91
+ @rtm.tasks.postpone :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id
92
+ end
93
+
94
+ def renameTask(id,newname)
95
+ v = findTask(id)
96
+ @rtm.tasks.setName :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id, :name => newname
97
+ end
98
+
99
+ def setDueDate(id,due)
100
+ v = findTask(id)
101
+ @rtm.tasks.setDueDate :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id, :due => due, :parse => 1
102
+ end
103
+
104
+ def setPriority(id, priority)
105
+ v = findTask(id)
106
+ @rtm.tasks.setPriority :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id, :priority => priority
107
+ end
108
+
109
+ def update(params)
110
+ v = findTask(params['id'])
111
+ @rtm.tasks.setDueDate :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id, :due => params['due'], :parse => 1
112
+ @rtm.tasks.setName :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id, :name => params['title']
113
+ @rtm.tasks.setPriority :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id, :priority => params['priority']
114
+ @rtm.tasks.complete :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id unless params['complete'].nil?
115
+ end
116
+
117
+ def getTimezone
118
+ sets = @rtm.settings.getList
119
+ return sets[:timezone]
120
+ end
121
+ end
122
+
123
+ class CommandLineInterface
124
+
125
+ def initialize(key,secret,token)
126
+ @rtm = Rrtm.new(key,secret,token)
127
+ end
128
+
129
+ def tasks
130
+ t = Array.new
131
+ if ARGV[1]
132
+ l = @rtm.findList(ARGV[1..-1].join(" "))
133
+ begin
134
+ tasks = @rtm.tasks :list_id => l
135
+ rescue Exception => e
136
+ puts e,"list not found"
137
+ return ''
138
+ end
139
+ else
140
+
141
+ tasks = @rtm.tasksAllTaskList
142
+
143
+ end
144
+ tasks.each do |key,val|
145
+ if val.class == RememberTheMilkHash
146
+ val.each do |k,v|
147
+ t.push(v) unless v.complete? # do not add c ompleted tasks
148
+ end
149
+ elsif val.class == RememberTheMilkTask
150
+ t.push(val) unless val.complete? # do not add c ompleted tasks
151
+ end
152
+ end
153
+
154
+ # sorting by date (inverse order) and than by task name
155
+ t.sort! do |a,b|
156
+ if (a.has_due? and b.has_due?)
157
+ a.due <=> b.due
158
+ elsif a.has_due?
159
+ -1
160
+ elsif b.has_due?
161
+ 1
162
+ else
163
+ a[:name] <=> b[:name]
164
+ end
165
+ end
166
+
167
+ # compose string result
168
+ t.each do |tt|
169
+ s = tt[:id] + ": " + tt[:name].to_s + " -- " + tt.due.to_s + "\n"
170
+ color(s,tt)
171
+ end
172
+ end
173
+
174
+ def color(s,t)
175
+ p = case t[:task][0][:priority]
176
+ when 'N' then printf("\e[0m%s\e[0m",s)
177
+ when '1' then printf("\e[31;40m%s\e[0m",s)
178
+ when '2' then printf("\e[33;40m%s\e[0m",s)
179
+ when '3' then printf("\e[32;40m%s\e[0m",s)
180
+ else puts "err"
181
+ end
182
+
183
+ end
184
+
185
+ def add
186
+ @rtm.addTask(ARGV[1..-1].join(" "))
187
+ end
188
+
189
+ def lists
190
+ l = @rtm.lists
191
+
192
+ l.each do |k,v|
193
+ puts v[:name]
194
+ end
195
+ end
196
+
197
+ def complete
198
+ begin
199
+ @rtm.completeTask(ARGV[1])
200
+ rescue
201
+ p "invalid task id"
202
+ end
203
+ end
204
+
205
+ def postpone
206
+ begin
207
+ @rtm.postponeTask(ARGV[1].chomp)
208
+ rescue Exception => e
209
+ p "invalid task id",e
210
+ end
211
+ end
212
+
213
+ def tz
214
+ return @rtm.getTimezone
215
+ end
216
+ def first
217
+ t = Array.new
218
+ tasks = @rtm.tasksAllTaskList
219
+
220
+ tasks.each do |key,val|
221
+ val.each do |k,v|
222
+ t.push(v) unless v.complete? # do not add c ompleted tasks
223
+ end
224
+ end
225
+
226
+ # sorting by date (inverse order) and than by task name
227
+ t.sort! do |a,b|
228
+ if (a.has_due? and b.has_due?)
229
+ a.due <=> b.due
230
+ elsif a.has_due?
231
+ -1
232
+ elsif b.has_due?
233
+ 1
234
+ else
235
+ a[:name] <=> b[:name]
236
+ end
237
+ end
238
+
239
+ # compose string result
240
+ s = ''
241
+ tt = t[0]
242
+ s += tt[:name].to_s + " -- " + tt.due.to_s + "\n"
243
+ puts s
244
+ end
245
+
246
+ def help
247
+ s = ''
248
+ s += 'Rrtm: Tha remember the milk Command Line Usage
249
+ usage rrtm <command> <params>
250
+
251
+ help: print this help and exits
252
+ lists: show available tasks lists
253
+ tasks [list name]: show not completed tasks
254
+ add <name>: name can be a task or in the form @list name@ task
255
+ add "<name>" : input is better parsed within quotes: task #Listname !priority_value(1..3)
256
+ complete <id>: mark task with id "id" as completed
257
+ postpone <id>: postpone task by one day
258
+ first: show first uncompleted task
259
+ '
260
+ puts s
261
+ end
262
+
263
+
264
+ end
265
+
266
+ #TODO gestione priorita' tasks
267
+ #TODO sort by priority?
268
+