sifttter-redux 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzE3MDQzODI1MTZjZmEwYzgwM2E5ZDFhMTNjM2EyYmRiNTUxNmE5Ng==
4
+ YjZhZTIzMTI3NTM1Mjc1MjFhZThiODc5ZmI2YmFkZjc4YTk2ZDY3Yw==
5
5
  data.tar.gz: !binary |-
6
- Y2I2Zjg4Y2JjYzcxM2NiYTM2NGNiODI2MTJiYmZlMTQ1MzgxM2MyMg==
6
+ OTAxYzExZjZjNDc1MmU5NjVkY2RkYjE1MTU3YzYwNDliMmU5Nzk2YQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTdiNTliOTI5ODNkMzA5NTZjY2RhMmRhYzFlMWNmYjQ4MTQwYzgzODJhYTlj
10
- NWI3OWIzYWIzMmNhMGNmYTFjNDZiZDBiZTdlNTdiZTgwNTRiNjMzNDQ1ODNm
11
- OTFkOWIyODQ4M2M5ZGZhZTQ3YjM1Y2Q3MDM5YWNlODk0ZDg3NTg=
9
+ NDA2Y2VmYTg4YWIzNTFkZTg0YjYyMTAyZGQ1ODM1Y2IzMjE0ZDA5NDkwZjIy
10
+ ZmQ2NDBhYzExYjIxMjVjM2U1NTY4NDkxYWY2ZmI4NjhlYWY3OTU3ZTVkMjE5
11
+ M2NiMTFjNTY5NTlmYTljYjY2ZWY4ZDVkZGM3NTk5MWRhNmFkMzE=
12
12
  data.tar.gz: !binary |-
13
- NTI0NGY4NTQyOTljMDE5MjkxN2RkYzU3ZDU0ZjhhZTA2YmM5NGU1YTVhYmE4
14
- OWU2YjAwYTkxYjQ3NzZhNjI2MDA2YjZhOGM1ODJjN2E2NWNkNjQ4NTE4ZTkz
15
- Mzc0YjM4ODJkYTU0MmVjZTcyNzkwNTJlMGZhM2M5ZjFkNDM2MDk=
13
+ NDEzOTY5YWZkZmMyZDBiOWRlNWVkOTNhZGNjYmVhNjAzNjFhMmExYTc0ZTgx
14
+ MDg1ODY4YTM0M2U4MzRkMzkzM2M3YzFiNzdlMGIzZDVhNjQ5ZTAwMjc1NTAz
15
+ MjI4NmMzN2IzMmRiMjcwMjJlODVlZGRiOWQ5YWZmMGUyMzg4NzY=
data/HISTORY.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.3.0
2
+
3
+ * Added ability to create entries for the past N days (not just 7)
4
+ * Added ability to create entries for the past N weeks
5
+ * Refactorings of existing DateRangeMaker class
6
+ * Additional documentation
7
+ * Fixed a bug with using Chronic's language parsing using `-f`
8
+
1
9
  # 0.2.5
2
10
 
3
11
  * Fixed a bug where execution could prematurely halt if no Day One entries were found
@@ -16,13 +24,13 @@
16
24
 
17
25
  # 0.2.1
18
26
 
19
- * Fixed a bug where the config manager would fail on certain platforms.
20
- * Fixed a bug where the path to Dropbox Uploader became malformed.
27
+ * Fixed a bug where the config manager would fail on certain platforms
28
+ * Fixed a bug where the path to Dropbox Uploader became malformed
21
29
 
22
30
  # 0.2.0
23
31
 
24
- * Implemented catch-up mode.
32
+ * Implemented catch-up mode
25
33
 
26
34
  # 0.1.0
27
35
 
28
- * Initial release of Sifttter Redux.
36
+ * Initial release of Sifttter Redux
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Sifttter Redux
2
2
  ==============
3
3
 
4
- Siftter Redux is a modification of Craig Eley's [Siftter](http://gist.github.com/craigeley/8301817 "Siftter"), a script to collect information from [IFTTT](http://www.ifttt.com "IFTTT") and place it in a [Day One](http://dayoneapp.com, "Day One") journal.
4
+ Siftter Redux is a modification of Craig Eley's [Sifttter](http://craigeley.com/post/72565974459/sifttter-an-ifttt-to-day-one-logger "Sifttter"), a script to collect information from [IFTTT](http://www.ifttt.com "IFTTT") and place it in a [Day One](http://dayoneapp.com, "Day One") journal.
5
5
 
6
6
  Siftter Redux's primary difference is in its execution method: it intended to run autonomously so that it does not need to be manually activated. This allows IFTTT data to be synchronized to Day One on a schedule.
7
7
 
@@ -70,42 +70,183 @@ Initialization will perform the following steps:
70
70
  3. The location on your filesystem where Day One files will be temporarily stored
71
71
  4. The location of your Day One files in Dropbox
72
72
 
73
- ### Basic Mode
73
+ ### Basic Execution
74
74
 
75
75
  ```
76
- # Creates an entry for today
77
76
  $ srd exec
77
+ #### EXECUTING...
78
+ ---> INFO: Creating entry for February 15, 2014...
79
+ ---> INFO: Downloading Sifttter files...DONE.
80
+ ---> SUCCESS: Entry logged for February 15, 2014...
81
+ ---> INFO: Uploading Day One entries to Dropbox...DONE.
82
+ ---> INFO: Removing downloaded Day One files...DONE.
83
+ ---> INFO: Removing downloaded Sifttter files...DONE.
84
+ #### EXECUTION COMPLETE!
78
85
  ```
79
86
 
80
87
  ### "Catch-up" Mode
81
88
 
82
- Sometimes, events occur that prevent Sifttter Redux from running (power loss to your device, a bad Cron job, etc.). In this case, Sifttter Redux's "catch-up" mode can be used to collect any valid journal data before the current day.
89
+ Sometimes, events occur that prevent Sifttter Redux from running (power loss to your device, a bad Cron job, etc.). In this case, Sifttter Redux's "catch-up" mode can be used to collect any valid journal on or before today's date.
83
90
 
84
- There are many ways to use this mode:
91
+ There are many ways to use this mode (note that "today" in these examples is **February 15, 2014**):
85
92
 
86
- #### 7-Day Catch-up
93
+ #### Yesterday Catch-up
87
94
 
88
- To create entries for the past 7 days (not inclusive of the current day):
95
+ To create an entry for yesterday:
89
96
 
90
97
  ```
91
- # Creates an entry for each day from from 7 days ago to yesterday
92
- $ srd exec -c
98
+ $ srd exec -y
99
+ #### EXECUTING...
100
+ ---> INFO: Creating entry for February 14, 2014...
101
+ ---> INFO: Downloading Sifttter files...DONE.
102
+ ---> SUCCESS: Entry logged for February 14, 2014...
103
+ ---> INFO: Uploading Day One entries to Dropbox...DONE.
104
+ ---> INFO: Removing downloaded Day One files...DONE.
105
+ ---> INFO: Removing downloaded Sifttter files...DONE.
106
+ #### EXECUTION COMPLETE!
93
107
  ```
94
108
 
95
- To include the current day:
109
+ #### Last "N" Days Catch-up
110
+
111
+ Sifttter Redux allows you to specify the number of days back it should look for new entries:
96
112
 
97
113
  ```
98
- # Creates an entry for each day from 7 days ago to today
99
- $ srd exec -c -i
114
+ $ srd exec -n 3
115
+ #### EXECUTING...
116
+ ---> INFO: Creating entries for dates from February 12, 2014 to February 14, 2014...
117
+ ---> INFO: Downloading Sifttter files...DONE.
118
+ ---> SUCCESS: Entry logged for February 12, 2014...
119
+ ---> SUCCESS: Entry logged for February 13, 2014...
120
+ ---> SUCCESS: Entry logged for February 14, 2014...
121
+ ---> INFO: Uploading Day One entries to Dropbox...DONE.
122
+ ---> INFO: Removing downloaded Day One files...DONE.
123
+ ---> INFO: Removing downloaded Sifttter files...DONE.
124
+ #### EXECUTION COMPLETE!
125
+
126
+ $ srd exec -n 12
127
+ ---> INFO: Creating entries for dates from February 03, 2014 to February 14, 2014...
128
+ ---> INFO: Downloading Sifttter files...DONE.
129
+ ---> SUCCESS: February 03, 2014...
130
+ ---> SUCCESS: February 04, 2014...
131
+ ---> SUCCESS: February 05, 2014...
132
+ ---> SUCCESS: February 06, 2014...
133
+ ---> SUCCESS: February 07, 2014...
134
+ ---> SUCCESS: February 08, 2014...
135
+ ---> SUCCESS: February 09, 2014...
136
+ ---> SUCCESS: February 10, 2014...
137
+ ---> SUCCESS: February 11, 2014...
138
+ ---> SUCCESS: February 12, 2014...
139
+ ---> SUCCESS: February 13, 2014...
140
+ ---> SUCCESS: February 14, 2014...
141
+ ---> INFO: Uploading Day One entries to Dropbox...DONE.
142
+ ---> INFO: Removing downloaded Day One files...DONE.
143
+ ---> INFO: Removing downloaded Sifttter files...DONE.
144
+ #### EXECUTION COMPLETE!
100
145
  ```
101
146
 
102
- #### Yesterday Catch-up
147
+ Note that this option goes until yesterday ("yesterday" because you might not be ready to have today's entries scanned). If you'd rather include today's date, you can always add the `-i` switch:
103
148
 
104
- To create an entry for yesterday:
149
+ ```
150
+ $ srd exec -i -n 3
151
+ #### EXECUTING...
152
+ ---> INFO: Creating entries for dates from February 12, 2014 to February 15, 2014...
153
+ ---> INFO: Downloading Sifttter files...DONE.
154
+ ---> SUCCESS: Entry logged for February 12, 2014...
155
+ ---> SUCCESS: Entry logged for February 13, 2014...
156
+ ---> SUCCESS: Entry logged for February 14, 2014...
157
+ ---> SUCCESS: Entry logged for February 15, 2014...
158
+ ---> INFO: Uploading Day One entries to Dropbox...DONE.
159
+ ---> INFO: Removing downloaded Day One files...DONE.
160
+ ---> INFO: Removing downloaded Sifttter files...DONE.
161
+ #### EXECUTION COMPLETE!
162
+ ```
163
+
164
+ #### Last "N" Weeks Catch-up
165
+
166
+ Sifttter Redux also allows you to specify a number of weeks back that should be scanned for new entries:
105
167
 
106
168
  ```
107
- # Creates an entry for yesterday
108
- $ srd exec -y
169
+ $ srd exec -w 1
170
+ #### EXECUTING...
171
+ ---> INFO: Creating entries for dates from February 03, 2014 to February 14, 2014...
172
+ ---> INFO: Downloading Sifttter files...DONE.
173
+ ---> SUCCESS: Entry logged for February 03, 2014...
174
+ ---> SUCCESS: Entry logged for February 04, 2014...
175
+ ---> SUCCESS: Entry logged for February 05, 2014...
176
+ ---> SUCCESS: Entry logged for February 06, 2014...
177
+ ---> SUCCESS: Entry logged for February 07, 2014...
178
+ ---> SUCCESS: Entry logged for February 08, 2014...
179
+ ---> SUCCESS: Entry logged for February 09, 2014...
180
+ ---> SUCCESS: Entry logged for February 10, 2014...
181
+ ---> SUCCESS: Entry logged for February 11, 2014...
182
+ ---> SUCCESS: Entry logged for February 12, 2014...
183
+ ---> SUCCESS: Entry logged for February 13, 2014...
184
+ ---> SUCCESS: Entry logged for February 14, 2014...
185
+ ---> INFO: Uploading Day One entries to Dropbox...DONE.
186
+ ---> INFO: Removing downloaded Day One files...DONE.
187
+ ---> INFO: Removing downloaded Sifttter files...DONE.
188
+ #### EXECUTION COMPLETE!
189
+
190
+ $ srd exec -w 3
191
+ #### EXECUTING...
192
+ ---> INFO: Creating entries for dates from January 20, 2014 to February 14, 2014...
193
+ ---> INFO: Downloading Sifttter files...DONE.
194
+ ---> SUCCESS: Entry logged for January 20, 2014...
195
+ ---> SUCCESS: Entry logged for January 21, 2014...
196
+ ---> SUCCESS: Entry logged for January 22, 2014...
197
+ ---> SUCCESS: Entry logged for January 23, 2014...
198
+ ---> SUCCESS: Entry logged for January 24, 2014...
199
+ ---> SUCCESS: Entry logged for January 25, 2014...
200
+ ---> SUCCESS: Entry logged for January 26, 2014...
201
+ ---> SUCCESS: Entry logged for January 27, 2014...
202
+ ---> SUCCESS: Entry logged for January 28, 2014...
203
+ ---> SUCCESS: Entry logged for January 29, 2014...
204
+ ---> SUCCESS: Entry logged for January 30, 2014...
205
+ ---> SUCCESS: Entry logged for January 31, 2014...
206
+ ---> SUCCESS: Entry logged for February 01, 2014...
207
+ ---> SUCCESS: Entry logged for February 02, 2014...
208
+ ---> SUCCESS: Entry logged for February 03, 2014...
209
+ ---> SUCCESS: Entry logged for February 04, 2014...
210
+ ---> SUCCESS: Entry logged for February 05, 2014...
211
+ ---> SUCCESS: Entry logged for February 06, 2014...
212
+ ---> SUCCESS: Entry logged for February 07, 2014...
213
+ ---> SUCCESS: Entry logged for February 08, 2014...
214
+ ---> SUCCESS: Entry logged for February 09, 2014...
215
+ ---> SUCCESS: Entry logged for February 10, 2014...
216
+ ---> SUCCESS: Entry logged for February 11, 2014...
217
+ ---> SUCCESS: Entry logged for February 12, 2014...
218
+ ---> SUCCESS: Entry logged for February 13, 2014...
219
+ ---> SUCCESS: Entry logged for February 14, 2014...
220
+ ---> INFO: Uploading Day One entries to Dropbox...DONE.
221
+ ---> INFO: Removing downloaded Day One files...DONE.
222
+ ---> INFO: Removing downloaded Sifttter files...DONE.
223
+ #### EXECUTION COMPLETE!
224
+ ```
225
+
226
+ As you'd expect, you can always add the `-i` switch:
227
+
228
+ ```
229
+ $ srd exec -i -w 1
230
+ #### EXECUTING...
231
+ ---> INFO: Creating entries for dates from February 03, 2014 to February 15, 2014...
232
+ ---> INFO: Downloading Sifttter files...DONE.
233
+ ---> SUCCESS: Entry logged for February 03, 2014...
234
+ ---> SUCCESS: Entry logged for February 04, 2014...
235
+ ---> SUCCESS: Entry logged for February 05, 2014...
236
+ ---> SUCCESS: Entry logged for February 06, 2014...
237
+ ---> SUCCESS: Entry logged for February 07, 2014...
238
+ ---> SUCCESS: Entry logged for February 08, 2014...
239
+ ---> SUCCESS: Entry logged for February 09, 2014...
240
+ ---> SUCCESS: Entry logged for February 10, 2014...
241
+ ---> SUCCESS: Entry logged for February 11, 2014...
242
+ ---> SUCCESS: Entry logged for February 12, 2014...
243
+ ---> SUCCESS: Entry logged for February 13, 2014...
244
+ ---> SUCCESS: Entry logged for February 14, 2014...
245
+ ---> SUCCESS: Entry logged for February 15, 2014...
246
+ ---> INFO: Uploading Day One entries to Dropbox...DONE.
247
+ ---> INFO: Removing downloaded Day One files...DONE.
248
+ ---> INFO: Removing downloaded Sifttter files...DONE.
249
+ #### EXECUTION COMPLETE!
109
250
  ```
110
251
 
111
252
  #### Date Range Catch-up
@@ -113,22 +254,79 @@ $ srd exec -y
113
254
  To create entries for a range of dates:
114
255
 
115
256
  ```
116
- # Creates an entry for each day from 2/1/2014 to 2/12/2014
117
257
  $ srd exec -f 2014-02-01 -t 2014-02-12
258
+ #### EXECUTING...
259
+ ---> INFO: Creating entries for dates from February 01, 2014 to February 12, 2014...
260
+ ---> INFO: Downloading Sifttter files...DONE.
261
+ ---> SUCCESS: Entry logged for February 01, 2014...
262
+ ---> SUCCESS: Entry logged for February 02, 2014...
263
+ ---> SUCCESS: Entry logged for February 03, 2014...
264
+ ---> SUCCESS: Entry logged for February 04, 2014...
265
+ ---> SUCCESS: Entry logged for February 05, 2014...
266
+ ---> SUCCESS: Entry logged for February 06, 2014...
267
+ ---> SUCCESS: Entry logged for February 07, 2014...
268
+ ---> SUCCESS: Entry logged for February 08, 2014...
269
+ ---> SUCCESS: Entry logged for February 09, 2014...
270
+ ---> SUCCESS: Entry logged for February 10, 2014...
271
+ ---> SUCCESS: Entry logged for February 11, 2014...
272
+ ---> SUCCESS: Entry logged for February 12, 2014...
273
+ ---> INFO: Uploading Day One entries to Dropbox...DONE.
274
+ ---> INFO: Removing downloaded Day One files...DONE.
275
+ ---> INFO: Removing downloaded Sifttter files...DONE.
276
+ #### EXECUTION COMPLETE!
118
277
  ```
119
278
 
120
279
  Even more simply, to create entries from a specific point until yesterday ("yesterday" because you might not be ready to have today's entries scanned):
121
280
 
122
281
  ```
123
- # Creates an entry for each day from 2/1/2014 to yesterday's date
124
282
  $ srd exec -f 2014-02-01
283
+ #### EXECUTING...
284
+ ---> INFO: Creating entries for dates from February 01, 2014 to February 12, 2014...
285
+ ---> INFO: Downloading Sifttter files...DONE.
286
+ ---> SUCCESS: Entry logged for February 01, 2014...
287
+ ---> SUCCESS: Entry logged for February 02, 2014...
288
+ ---> SUCCESS: Entry logged for February 03, 2014...
289
+ ---> SUCCESS: Entry logged for February 04, 2014...
290
+ ---> SUCCESS: Entry logged for February 05, 2014...
291
+ ---> SUCCESS: Entry logged for February 06, 2014...
292
+ ---> SUCCESS: Entry logged for February 07, 2014...
293
+ ---> SUCCESS: Entry logged for February 08, 2014...
294
+ ---> SUCCESS: Entry logged for February 09, 2014...
295
+ ---> SUCCESS: Entry logged for February 10, 2014...
296
+ ---> SUCCESS: Entry logged for February 11, 2014...
297
+ ---> SUCCESS: Entry logged for February 12, 2014...
298
+ ---> INFO: Uploading Day One entries to Dropbox...DONE.
299
+ ---> INFO: Removing downloaded Day One files...DONE.
300
+ ---> INFO: Removing downloaded Sifttter files...DONE.
301
+ #### EXECUTION COMPLETE!
125
302
  ```
126
303
 
127
- Of course, if you want to include today's date, you can always use the trusty `-i` switch:
304
+ In this case, once more, you can use the trusty `-i` switch if you want:
128
305
 
129
306
  ```
130
- # Creates an entry for each day from 2/1/2014 to today's date
131
- $ srd exec -f 2014-02-01 -i
307
+ $ srd exec -i -f 2014-02-01
308
+ #### EXECUTING...
309
+ ---> INFO: Creating entries for dates from February 01, 2014 to February 15, 2014...
310
+ ---> INFO: Downloading Sifttter files...DONE.
311
+ ---> SUCCESS: Entry logged for February 01, 2014...
312
+ ---> SUCCESS: Entry logged for February 02, 2014...
313
+ ---> SUCCESS: Entry logged for February 03, 2014...
314
+ ---> SUCCESS: Entry logged for February 04, 2014...
315
+ ---> SUCCESS: Entry logged for February 05, 2014...
316
+ ---> SUCCESS: Entry logged for February 06, 2014...
317
+ ---> SUCCESS: Entry logged for February 07, 2014...
318
+ ---> SUCCESS: Entry logged for February 08, 2014...
319
+ ---> SUCCESS: Entry logged for February 09, 2014...
320
+ ---> SUCCESS: Entry logged for February 10, 2014...
321
+ ---> SUCCESS: Entry logged for February 11, 2014...
322
+ ---> SUCCESS: Entry logged for February 12, 2014...
323
+ ---> SUCCESS: Entry logged for February 13, 2014...
324
+ ---> SUCCESS: Entry logged for February 14, 2014...
325
+ ---> SUCCESS: Entry logged for February 15, 2014...
326
+ ---> INFO: Uploading Day One entries to Dropbox...DONE.
327
+ ---> INFO: Removing downloaded Day One files...DONE.
328
+ ---> INFO: Removing downloaded Sifttter files...DONE.
329
+ #### EXECUTION COMPLETE!
132
330
  ```
133
331
 
134
332
  Two notes to be aware of:
@@ -139,8 +337,19 @@ Two notes to be aware of:
139
337
  Sifttter Redux makes use of the excellent [Chronic gem](https://github.com/mojombo/chronic "Chronic"), which provides natural language parsing for dates and times. This means that you can run commands with more "human" dates:
140
338
 
141
339
  ```
142
- # Natural language parsing is great! Thanks, Chronic!
143
- $ srd exec -f "last Thursday" -t "yesterday"
340
+ $ srd exec -f "last monday" -t "yesterday"
341
+ #### EXECUTING...
342
+ ---> INFO: Creating entries for dates from February 10, 2014 to February 14, 2014...
343
+ ---> INFO: Downloading Sifttter files...DONE.
344
+ ---> SUCCESS: Entry logged for February 10, 2014...
345
+ ---> SUCCESS: Entry logged for February 11, 2014...
346
+ ---> SUCCESS: Entry logged for February 12, 2014...
347
+ ---> SUCCESS: Entry logged for February 13, 2014...
348
+ ---> SUCCESS: Entry logged for February 14, 2014...
349
+ ---> INFO: Uploading Day One entries to Dropbox...DONE.
350
+ ---> INFO: Removing downloaded Day One files...DONE.
351
+ ---> INFO: Removing downloaded Sifttter files...DONE.
352
+ #### EXECUTION COMPLETE!
144
353
  ```
145
354
 
146
355
  See [Chronic's Examples section](https://github.com/mojombo/chronic#examples "Chronic Examples") for more examples.
data/Rakefile CHANGED
@@ -1,44 +1,9 @@
1
1
  require 'rake/clean'
2
- require 'rubygems'
3
- require 'rubygems/package_task'
4
- require 'rdoc/task'
5
- require 'cucumber'
6
- require 'cucumber/rake/task'
7
- Rake::RDocTask.new do |rd|
8
- rd.main = "README.rdoc"
9
- rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
10
- rd.title = 'Your application title'
11
- end
12
-
13
- spec = eval(File.read('sifttter-redux.gemspec'))
14
-
15
- Gem::PackageTask.new(spec) do |pkg|
16
- end
17
- CUKE_RESULTS = 'results.html'
18
- CLEAN << CUKE_RESULTS
19
- desc 'Run features'
20
- Cucumber::Rake::Task.new(:features) do |t|
21
- opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
22
- opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
23
- t.cucumber_opts = opts
24
- t.fork = false
25
- end
26
-
27
- desc 'Run features tagged as work-in-progress (@wip)'
28
- Cucumber::Rake::Task.new('features:wip') do |t|
29
- tag_opts = ' --tags ~@pending'
30
- tag_opts = ' --tags @wip'
31
- t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
32
- t.fork = false
33
- end
34
-
35
- task :cucumber => :features
36
- task 'cucumber:wip' => 'features:wip'
37
- task :wip => 'features:wip'
38
2
  require 'rake/testtask'
3
+
39
4
  Rake::TestTask.new do |t|
40
5
  t.libs << "test"
41
6
  t.test_files = FileList['test/*_test.rb']
42
7
  end
43
8
 
44
- task :default => [:test,:features]
9
+ task :default => [:test]
data/bin/srd CHANGED
@@ -92,54 +92,76 @@ desc 'Execute the script'
92
92
  command :exec do |c|
93
93
 
94
94
  c.flag(
95
- [:f, :from],
95
+ [:f],
96
96
  :desc => 'Run catch-up mode with this start date',
97
97
  )
98
98
 
99
99
  c.flag(
100
- [:t, :to],
101
- :desc => 'Run catch-up mode with this end date (must be accompanied by --from)',
100
+ [:n],
101
+ :desc => 'Run catch-up mode for the last N days'
102
+ )
103
+
104
+ c.flag(
105
+ [:t],
106
+ :desc => 'Run catch-up mode with this end date (must be accompanied by -f)',
107
+ )
108
+
109
+ c.flag(
110
+ [:w],
111
+ :desc => 'Run catch-up mode for the last N weeks'
102
112
  )
103
113
 
104
114
  c.switch(
105
- [:c, :last_7_days],
106
- :desc => 'Run catch-up mode for the last 7 days'
115
+ [:c],
116
+ :desc => 'Run catch-up mode for the current week (i.e., the beginning of the week to yesterday)'
107
117
  )
108
118
 
109
119
  c.switch(
110
- [:i, :include_today],
120
+ [:i],
111
121
  :desc => 'Include today\'s date in catch-up'
112
122
  )
113
123
 
114
124
  c.switch(
115
- [:y, :yesterday],
125
+ [:y],
116
126
  :desc => 'Run catch-up mode for yesterday'
117
127
  )
118
128
 
119
129
  c.action do |global_options, options, args|
120
130
  command_complete = false
121
-
131
+
122
132
  CliMessage.section('EXECUTING...')
133
+
134
+ if (options[:c] || options[:n] || options[:w] || options[:y] || options[:f] || options[:t])
123
135
 
124
- if (options[:c] || options[:y] || options[:f] || options[:t])
136
+ # Current Week
125
137
  if (!command_complete && options[:c])
126
- dates = $date_range_maker.last_seven_days(options[:i])
138
+ dates = $date_range_maker.last_n_weeks(0, {:include_today => options[:i]})
127
139
  command_complete = true
128
140
  end
129
141
 
142
+ # Last N Days
143
+ if (!command_complete && options[:n])
144
+ dates = $date_range_maker.last_n_days(options[:n].to_i, {:include_today => options[:i]})
145
+ command_complete = true
146
+ end
147
+
148
+ # Yesterday
130
149
  if (!command_complete && options[:y])
131
150
  dates = $date_range_maker.yesterday
132
151
  command_complete = true
133
152
  end
134
153
 
154
+ # Last N Weeks
155
+ if (!command_complete && options[:w])
156
+ dates = $date_range_maker.last_n_weeks(options[:w].to_i, {:include_today => options[:i]})
157
+ command_complete = true
158
+ end
159
+
160
+ # Specific Range
135
161
  if (!command_complete && (options[:f] || options[:t]))
136
162
  begin
137
- dates = $date_range_maker.range({
138
- :start_date => options[:f],
139
- :end_date => options[:t],
140
- :include_today => options[:i],
141
- })
142
-
163
+ dates = $date_range_maker.range(options[:f], options[:t], {:include_today => options[:i]})
164
+
143
165
  if (dates.last > Date.today)
144
166
  CliMessage.warning("Ignoring overextended end date and using today's date (#{Date.today})")
145
167
  dates = (dates.first..Date.today)
@@ -155,13 +177,21 @@ command :exec do |c|
155
177
  end
156
178
 
157
179
  if (!dates.nil?)
158
- CliMessage.info("Creating entries for dates from #{dates.first} to #{dates.reverse_each.first}...")
180
+ first_date = dates.first
181
+ second_date = dates.reverse_each.first
182
+
183
+ if (first_date == second_date)
184
+ CliMessage.info("Creating entry for #{first_date.strftime('%B %d, %Y')}...")
185
+ else
186
+ CliMessage.info("Creating entries for dates from #{first_date.strftime('%B %d, %Y')} to #{second_date.strftime('%B %d, %Y')}...")
187
+ end
159
188
 
160
189
  download_sifttter_files
161
190
 
162
191
  dates.each do |date|
163
192
  run_sifttter(date)
164
193
  end
194
+
165
195
  # Upload any Day One entries to Dropbox (if there are any).
166
196
  if (!Dir[$config.sifttter_redux["dayone_local_filepath"] + "/*"].empty?)
167
197
  CliMessage.info("Uploading Day One entries to Dropbox...", false)
@@ -1,5 +1,5 @@
1
1
  module SifttterRedux
2
- VERSION = "0.2.5"
2
+ VERSION = "0.3.0"
3
3
 
4
4
  # Sifttter and Sifttter Redux Constants
5
5
  SRD_CONFIG_FILEPATH = File.join(ENV['HOME'], '.sifttter_redux')
@@ -1,29 +1,51 @@
1
+ require 'active_support/core_ext'
1
2
  require 'chronic'
2
3
 
4
+ #| ======================================================
5
+ #| DateRangeMakerError Class
6
+ #| ======================================================
3
7
  class DateRangeMakerError < StandardError
4
8
  def initialize(msg = "You've triggered a DateRangeMakerError")
5
9
  super
6
10
  end
7
11
  end
8
12
 
13
+ #| ======================================================
14
+ #| BadChronicDateError Class
15
+ #| ======================================================
9
16
  class BadChronicDateError < DateRangeMakerError
10
17
  def initialize(msg = "Invalid date provided to Chronic...")
11
18
  super
12
19
  end
13
20
  end
14
21
 
22
+ #| ======================================================
23
+ #| BadDateOrderError Class
24
+ #| ======================================================
15
25
  class BadDateOrderError < DateRangeMakerError
16
26
  def initialize(msg = "The start date must be before or equal to the end date...")
17
27
  super
18
28
  end
19
29
  end
20
30
 
31
+ #| ======================================================
32
+ #| InvalidFlagsError Class
33
+ #| ======================================================
21
34
  class InvalidFlagsError < DateRangeMakerError
22
35
  def initialize(msg = "You can't specify -t without specifying -f...")
23
36
  super
24
37
  end
25
38
  end
26
39
 
40
+ #| ======================================================
41
+ #| NegativeDaysError Class
42
+ #| ======================================================
43
+ class NegativeDaysError < DateRangeMakerError
44
+ def initialize(msg = "You must specify a positive number of days to look back...")
45
+ super
46
+ end
47
+ end
48
+
27
49
  #| ======================================================
28
50
  #| DateRangeMaker Class
29
51
  #|
@@ -32,25 +54,98 @@ end
32
54
  #| ======================================================
33
55
  class DateRangeMaker
34
56
 
57
+ #| ------------------------------------------------------
58
+ #| initialize method
59
+ #| @return Void
60
+ #| ------------------------------------------------------
35
61
  def initialize
36
62
 
37
63
  end
38
64
 
39
- def last_seven_days(include_today = false)
40
- if (include_today)
41
- _r = (Date.today - 7..Date.today)
65
+ #| ------------------------------------------------------
66
+ #| last_n_days method
67
+ #|
68
+ #| Returns a date range for the last N days (including
69
+ #| today's date if specified).
70
+ #| @param num_days The number of days to look back
71
+ #| @param options Miscellaneous options hash
72
+ #| @return Range
73
+ #| ------------------------------------------------------
74
+ def last_n_days(num_days, options = {})
75
+ raise NegativeDaysError if num_days < 0
76
+
77
+ opts = {
78
+ :include_today => false
79
+ }
80
+
81
+ options.each do |k, v|
82
+ k = k.to_sym
83
+ raise ArgumentError, "Unknown property: #{k}" unless opts.key?(k)
84
+ opts[k] = v
85
+ end
86
+
87
+ if (opts[:include_today])
88
+ _r = (Date.today - num_days..Date.today)
42
89
  else
43
- _r = (Date.today - 7...Date.today)
90
+ _r = (Date.today - num_days...Date.today)
44
91
  end
45
92
 
46
93
  return _r
47
94
  end
48
95
 
49
- def range(options = {})
96
+ #| ------------------------------------------------------
97
+ #| last_n_weeks method
98
+ #|
99
+ #| Returns a date range for the last N weeks (including
100
+ #| today's date if specified).
101
+ #| @param num_days The number of weeks to look back
102
+ #| @param options Miscellaneous options hash
103
+ #| @return Range
104
+ #| ------------------------------------------------------
105
+ def last_n_weeks(num_weeks = 0, options = {})
106
+ raise NegativeDaysError if num_weeks < 0
107
+
108
+ opts = {
109
+ :include_today => false
110
+ }
111
+
112
+ options.each do |k, v|
113
+ k = k.to_sym
114
+ raise ArgumentError, "Unknown property: #{k}" unless opts.key?(k)
115
+ opts[k] = v
116
+ end
117
+
118
+ beginning_date = Date.today.at_beginning_of_week
119
+ end_date = Date.today.at_end_of_week
50
120
 
121
+ # We're currently before the end of the week, so
122
+ # reset the new ending date to today.
123
+ if (end_date > Date.today)
124
+ end_date = Date.today
125
+ end
126
+
127
+ if (opts[:include_today])
128
+ _r = (beginning_date - num_weeks.week..end_date)
129
+ else
130
+ _r = (beginning_date - num_weeks.week...end_date)
131
+ end
132
+
133
+ return _r
134
+ end
135
+
136
+ #| ------------------------------------------------------
137
+ #| range method
138
+ #|
139
+ #| Returns a date range for specified start dates and
140
+ #| end dates. Note that specifying an end date greater
141
+ #| than today's date will force today to be the end date.
142
+ #| @param start_date The start date
143
+ #| @param end_date The end date
144
+ #| @param options Miscellaneous options hash
145
+ #| @return Range
146
+ #| ------------------------------------------------------
147
+ def range(start_date, end_date, options = {})
51
148
  opts = {
52
- :start_date => Date.today,
53
- :end_date => nil,
54
149
  :include_today => false
55
150
  }
56
151
 
@@ -61,20 +156,20 @@ class DateRangeMaker
61
156
  end
62
157
 
63
158
  begin
64
- chronic_start_date = Chronic.parse(opts[:start_date]).to_date
159
+ chronic_start_date = Chronic.parse(start_date).to_date
65
160
  rescue
66
- raise BadChronicDateError.new("Invalid date provided to Chronic: #{opts[:start_date]}") if !opts[:start_date].nil?
161
+ raise BadChronicDateError.new("Invalid date provided to Chronic: #{start_date}") if !start_date.nil?
67
162
  nil
68
163
  end
69
164
 
70
165
  begin
71
- chronic_end_date = Chronic.parse(opts[:end_date]).to_date
166
+ chronic_end_date = Chronic.parse(end_date).to_date
72
167
  rescue
73
- raise BadChronicDateError.new("Invalid date provided to Chronic: #{opts[:end_date]}") if !opts[:end_date].nil?
168
+ raise BadChronicDateError.new("Invalid date provided to Chronic: #{end_date}") if !end_date.nil?
74
169
  nil
75
170
  end
76
171
 
77
- raise InvalidFlagsError.new if (opts[:start_date].nil? && !opts[:end_date].nil?)
172
+ raise InvalidFlagsError.new if (start_date.nil? && !end_date.nil?)
78
173
  raise BadDateOrderError.new if (chronic_end_date && chronic_start_date > chronic_end_date)
79
174
 
80
175
  if (!chronic_start_date.nil?)
@@ -92,10 +187,22 @@ class DateRangeMaker
92
187
  return dates
93
188
  end
94
189
 
190
+ #| ------------------------------------------------------
191
+ #| today method
192
+ #|
193
+ #| Returns a date range for today
194
+ #| @return Range
195
+ #| ------------------------------------------------------
95
196
  def today
96
197
  return (Date.today..Date.today)
97
198
  end
98
199
 
200
+ #| ------------------------------------------------------
201
+ #| yesterday method
202
+ #|
203
+ #| Returns a date range for yesterday
204
+ #| @return Range
205
+ #| ------------------------------------------------------
99
206
  def yesterday
100
207
  return (Date.today - 1..Date.today - 1)
101
208
  end
@@ -22,6 +22,7 @@ spec = Gem::Specification.new do |s|
22
22
  s.extra_rdoc_files = %w[README.md HISTORY.md LICENSE]
23
23
 
24
24
  s.add_development_dependency('rake', '~> 0')
25
+ s.add_runtime_dependency('activesupport', '~> 0')
25
26
  s.add_runtime_dependency('chronic', '0.10.2')
26
27
  s.add_runtime_dependency('colored','1.2')
27
28
  s.add_runtime_dependency('gli','2.9.0')
@@ -1,3 +1,4 @@
1
+ require 'active_support/core_ext'
1
2
  require 'date'
2
3
  require 'test_helper'
3
4
  require File.join(File.dirname(__FILE__), '..', 'lib/sifttter-redux/date-range-maker.rb')
@@ -16,41 +17,91 @@ class DefaultTest < Test::Unit::TestCase
16
17
  assert_equal($drm.yesterday, (Date.today - 1..Date.today - 1))
17
18
  end
18
19
 
19
- def test_last_7_days
20
- assert_equal($drm.last_seven_days, (Date.today - 7...Date.today))
20
+ def test_last_5_days
21
+ assert_equal($drm.last_n_days(5), (Date.today - 5...Date.today))
21
22
  end
22
23
 
23
- def test_last_7_days_include_today
24
- assert_equal($drm.last_seven_days(true), (Date.today - 7..Date.today))
24
+ def test_last_5_days_include_today
25
+ assert_equal($drm.last_n_days(5, {:include_today => true}), (Date.today - 5..Date.today))
26
+ end
27
+
28
+ def test_last_12_days
29
+ assert_equal($drm.last_n_days(12), (Date.today - 12...Date.today))
30
+ end
31
+
32
+ def test_last_12_days_include_today
33
+ assert_equal($drm.last_n_days(12, {:include_today => true}), (Date.today - 12..Date.today))
34
+ end
35
+
36
+ def test_current_week
37
+ end_date = Date.today.at_end_of_week
38
+ if Date.today.at_end_of_week > Date.today
39
+ end_date = Date.today
40
+ end
41
+
42
+ assert_equal($drm.last_n_weeks, (Date.today.at_beginning_of_week...end_date))
43
+ end
44
+
45
+ def test_current_week_include_today
46
+ end_date = Date.today.at_end_of_week
47
+ if Date.today.at_end_of_week > Date.today
48
+ end_date = Date.today
49
+ end
50
+
51
+ assert_equal($drm.last_n_weeks(0, {:include_today => true}), (Date.today.at_beginning_of_week..end_date))
52
+ end
53
+
54
+ def test_last_2_weeks
55
+ end_date = Date.today.at_end_of_week
56
+ if Date.today.at_end_of_week > Date.today
57
+ end_date = Date.today
58
+ end
59
+
60
+ assert_equal($drm.last_n_weeks(2), (Date.today.at_beginning_of_week - 2.week...end_date))
61
+ end
62
+
63
+ def test_last_2_weeks_include_today
64
+ end_date = Date.today.at_end_of_week
65
+ if Date.today.at_end_of_week > Date.today
66
+ end_date = Date.today
67
+ end
68
+
69
+ assert_equal($drm.last_n_weeks(2, {:include_today => true}), (Date.today.at_beginning_of_week - 2.week..end_date))
25
70
  end
26
71
 
27
72
  def test_range_only_start_date
28
- assert_equal($drm.range({:start_date => "2014-02-01"}), (Date.parse("2014-02-01")...Date.today))
73
+ assert_equal($drm.range("2014-02-01", nil), (Date.parse("2014-02-01")...Date.today))
29
74
  end
30
75
 
31
76
  def test_range_only_start_date_include_today
32
- assert_equal($drm.range({:start_date => "2014-02-01", :include_today => true}), (Date.parse("2014-02-01")..Date.today))
77
+ assert_equal($drm.range("2014-02-01", nil, {:include_today => true}), (Date.parse("2014-02-01")..Date.today))
33
78
  end
34
79
 
35
80
  def test_range_start_date_and_end_date
36
- assert_equal($drm.range({:start_date => "2014-02-01", :end_date => "2014-02-05"}), (Date.parse("2014-02-01")..Date.parse("2014-02-05")))
81
+ assert_equal($drm.range("2014-02-01", "2014-02-05"), (Date.parse("2014-02-01")..Date.parse("2014-02-05")))
37
82
  end
38
83
 
39
84
  def test_range_bad_dates
40
85
  assert_raise BadChronicDateError do
41
- $drm.range({:start_date => "Bad Start Date", :end_date => "Bad End Date"})
86
+ $drm.range("Bad Start Date", "Bad End Date")
42
87
  end
43
88
  end
44
89
 
45
90
  def test_range_end_date_with_no_start_date
46
91
  assert_raise InvalidFlagsError do
47
- $drm.range({:start_date => nil, :end_date => Date.today})
92
+ $drm.range(nil, Date.today)
48
93
  end
49
94
  end
50
95
 
51
96
  def test_range_end_date_before_start_date
52
97
  assert_raise BadDateOrderError do
53
- $drm.range({:start_date => Date.today, :end_date => Date.today - 1})
98
+ $drm.range(Date.today, Date.today - 1)
99
+ end
100
+ end
101
+
102
+ def test_range_negative_look_back
103
+ assert_raise NegativeDaysError do
104
+ $drm.last_n_days(-5)
54
105
  end
55
106
  end
56
107
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sifttter-redux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Bach
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: chronic
29
43
  requirement: !ruby/object:Gem::Requirement