sifttter-redux 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +8 -0
- data/HISTORY.md +7 -0
- data/LICENSE +21 -0
- data/README.md +227 -0
- data/Rakefile +44 -0
- data/Sifttter-Redux.gemspec +30 -0
- data/bin/srd +212 -0
- data/lib/Sifttter-Redux/cli-message.rb +135 -0
- data/lib/Sifttter-Redux/config-manager.rb +136 -0
- data/lib/Sifttter-Redux/constants.rb +15 -0
- data/lib/Sifttter-Redux/date-range-maker.rb +102 -0
- data/lib/Sifttter-Redux/methods.rb +190 -0
- data/lib/Sifttter-Redux/os.rb +47 -0
- data/lib/Sifttter-Redux.rb +6 -0
- data/test/catch_up_test.rb +56 -0
- data/test/test_helper.rb +9 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MzllODE5NmRmZjBmZWQ3OGI0N2Q0M2M2MDhiZjBlN2YxY2Y0NzllZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTA2YjEzMGQ1YjI5MzZmNzUwNWFlY2NmMmVkYjgyNGJjYWY2ODU5NQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmU3N2U3OGNhMzNmYmJlNDA3MWU0MzMwYjdjZGY5NWYxODA0ZmFiNWEwOWY4
|
10
|
+
ZDVlNDFkYjhlMWYwYzYyOWZiNDQ3MDEwY2MzYWEyY2IwMjA1YjQ3N2I2OGI5
|
11
|
+
MzdiYjc3ZDRhNTkzMjJiNzUxNTFkYWE2NTMwYTRmY2VhYjNiNGI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YzE2YjJmMmI2ZTRjMGY0Yzk2NzU3MGQ3ZjE0Zjk0MWQzZTU3NGU5Y2U0YTRm
|
14
|
+
Mjc1NmVlZDJkNzdhOTExNGYxMTFjNDhiMTc5NGY5YmM1Y2JmMjIwYTdhYjk3
|
15
|
+
MTVlZjVjNDliZWY0YTZmZGE2OTdhYzhlZjhlNzdlNzcyNTUzZDc=
|
data/.gitignore
ADDED
data/HISTORY.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) Tom Preston-Werner
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
Sifttter Redux
|
2
|
+
==============
|
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.
|
5
|
+
|
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
|
+
|
8
|
+
The aim of this project was to use a Raspberry Pi; as such, the instructions below are specifically catered to that platform. That said, it should be possible to install and configure on any *NIX platform.
|
9
|
+
|
10
|
+
## Prerequisites
|
11
|
+
|
12
|
+
There are three prerequisites needed to run Sifttter Redux:
|
13
|
+
|
14
|
+
* Ruby (version 1.9.3 or greater)
|
15
|
+
* Git
|
16
|
+
* UUID
|
17
|
+
|
18
|
+
These packages must be installed on your system before running Sifttter Redux. To install these packages on Raspbian:
|
19
|
+
|
20
|
+
```
|
21
|
+
$ sudo apt-get install ruby
|
22
|
+
$ sudo apt-get install git-core
|
23
|
+
$ sudo apt-get install uuid
|
24
|
+
```
|
25
|
+
|
26
|
+
## Installation
|
27
|
+
|
28
|
+
First, clone this repository via git:
|
29
|
+
|
30
|
+
```
|
31
|
+
$ git clone https://github.com/bachya/Sifttter-Redux.git
|
32
|
+
```
|
33
|
+
|
34
|
+
Next, cd into the Sifttter Redux directory and install the necessary gems:
|
35
|
+
|
36
|
+
```
|
37
|
+
$ cd Sifttter-Redux
|
38
|
+
$ bundle install
|
39
|
+
```
|
40
|
+
|
41
|
+
*(note that you may want to run `bundle install --global` for the sake of `cron` -- [see below](#cron-job))*
|
42
|
+
|
43
|
+
Finally, make sure the script is executable and initialize it:
|
44
|
+
|
45
|
+
```
|
46
|
+
$ chmod +x srd
|
47
|
+
$ ./srd init
|
48
|
+
```
|
49
|
+
|
50
|
+
## Usage
|
51
|
+
|
52
|
+
Syntax and usage can be accessed by running `./srd help`:
|
53
|
+
|
54
|
+
```
|
55
|
+
$ ./srd help
|
56
|
+
NAME
|
57
|
+
srd - Sifttter Redux v1.1
|
58
|
+
|
59
|
+
A modification of Craig Eley's Sifttter that allows for smart
|
60
|
+
installation on a standalone *NIX device (such as a Raspberry Pi).
|
61
|
+
|
62
|
+
SYNOPSIS
|
63
|
+
srd [global options] command [command options] [arguments...]
|
64
|
+
|
65
|
+
GLOBAL OPTIONS
|
66
|
+
--help - Show this message
|
67
|
+
|
68
|
+
COMMANDS
|
69
|
+
exec - Execute the script
|
70
|
+
help - Shows a list of commands or help for one command
|
71
|
+
init - Install and initialize dependencies
|
72
|
+
```
|
73
|
+
|
74
|
+
### Initialization
|
75
|
+
|
76
|
+
```
|
77
|
+
$ ./srd init
|
78
|
+
```
|
79
|
+
|
80
|
+
Initialization will perform the following steps:
|
81
|
+
|
82
|
+
1. Download [Dropbox-Uploader](https://github.com/andreafabrizi/Dropbox-Uploader "Dropbox-Uploder") to a location of your choice.
|
83
|
+
2. Collect some user preferences:
|
84
|
+
1. The location on your filesystem where Sifttter files will be temporarily stored
|
85
|
+
2. The location of your Sifttter files in Dropbox
|
86
|
+
3. The location on your filesystem where Day One files will be temporarily stored
|
87
|
+
4. The location of your Day One files in Dropbox
|
88
|
+
|
89
|
+
### Basic Mode
|
90
|
+
|
91
|
+
```
|
92
|
+
# Creates an entry for today
|
93
|
+
$ ./srd exec
|
94
|
+
```
|
95
|
+
|
96
|
+
### "Catch-up" Mode
|
97
|
+
|
98
|
+
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.
|
99
|
+
|
100
|
+
There are many ways to use this mode:
|
101
|
+
|
102
|
+
#### 7-Day Catch-up
|
103
|
+
|
104
|
+
To create entries for the past 7 days (not inclusive of the current day):
|
105
|
+
|
106
|
+
```
|
107
|
+
# Creates an entry for each day from from 7 days ago to yesterday
|
108
|
+
$ ./srd exec -c
|
109
|
+
```
|
110
|
+
|
111
|
+
To include the current day:
|
112
|
+
|
113
|
+
```
|
114
|
+
# Creates an entry for each day from 7 days ago to today
|
115
|
+
$ ./srd exec -c -i
|
116
|
+
```
|
117
|
+
|
118
|
+
#### Yesterday Catch-up
|
119
|
+
|
120
|
+
To create an entry for yesterday:
|
121
|
+
|
122
|
+
```
|
123
|
+
# Creates an entry for yesterday
|
124
|
+
$ ./srd exec -y
|
125
|
+
```
|
126
|
+
|
127
|
+
#### Date Range Catch-up
|
128
|
+
|
129
|
+
To create entries for a range of dates:
|
130
|
+
|
131
|
+
```
|
132
|
+
# Creates an entry for each day from 2/1/2014 to 2/12/2014
|
133
|
+
$ ./srd exec -f 2014-02-01 -t 2014-02-12
|
134
|
+
```
|
135
|
+
|
136
|
+
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):
|
137
|
+
|
138
|
+
```
|
139
|
+
# Creates an entry for each day from 2/1/2014 to yesterday's date
|
140
|
+
$ ./srd exec -f 2014-02-01
|
141
|
+
```
|
142
|
+
|
143
|
+
Of course, if you want to include today's date, you can always use the trusty `-i` switch:
|
144
|
+
|
145
|
+
```
|
146
|
+
# Creates an entry for each day from 2/1/2014 to today's date
|
147
|
+
$ ./srd exec -f 2014-02-01 -i
|
148
|
+
```
|
149
|
+
|
150
|
+
Two notes to be aware of:
|
151
|
+
|
152
|
+
* `-f` and `-t` are *inclusive* parameters, meaning that when specified, those dates will be included when searching for Siftter data.
|
153
|
+
* Although you can specify `-f` by itself, you cannot specify `-t` by itself.
|
154
|
+
|
155
|
+
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:
|
156
|
+
|
157
|
+
```
|
158
|
+
# Natural language parsing is great! Thanks, Chronic!
|
159
|
+
$ ./srd exec -f "last Thursday" -t "yesterday"
|
160
|
+
```
|
161
|
+
|
162
|
+
See [Chronic's Examples section](https://github.com/mojombo/chronic#examples "Chronic Examples") for more examples.
|
163
|
+
|
164
|
+
## Cron Job
|
165
|
+
|
166
|
+
By installing an entry to the Raspberry Pi's `crontab`, Sifttter Redux can be run automatically on a schedule.
|
167
|
+
|
168
|
+
One issue that arises is the loading of the bundled gems; because `cron` runs in a limited environment, it does not automatically know where to find installed gems.
|
169
|
+
|
170
|
+
### Using RVM
|
171
|
+
|
172
|
+
If your Raspberry Pi uses RVM, this `crontab` entry will do:
|
173
|
+
|
174
|
+
```
|
175
|
+
55 23 * * * /bin/bash -l -c 'source "$HOME/.rvm/scripts/rvm" && "$HOME/Sifttter-Redux/srd" exec'
|
176
|
+
```
|
177
|
+
|
178
|
+
### Globally Installing Bundled Gems
|
179
|
+
|
180
|
+
Another option is to install the bundled gems to the global gemset:
|
181
|
+
|
182
|
+
```
|
183
|
+
$ bundle install --global
|
184
|
+
```
|
185
|
+
|
186
|
+
## Known Issues
|
187
|
+
|
188
|
+
* Sifttter Redux makes no effort to see if entries already exist in Day One for a particular date. This means that if you're not careful, you might end up with duplicate entries. A future version will address this.
|
189
|
+
* At indeterminiate times (usually when in catch-up mode), Sifttter Redux will upload a file to Day One that Day One fails to read. Uncertain of the cause at this stage, but it's happened a few times.
|
190
|
+
|
191
|
+
## Future Releases
|
192
|
+
|
193
|
+
Some functionality I would like to tackle for future releases:
|
194
|
+
|
195
|
+
* Interactive cron job installer
|
196
|
+
* Verbose mode that more explicity tells the user what's currently going on
|
197
|
+
* Automatic gem bundling
|
198
|
+
|
199
|
+
## Bugs and Feature Requests
|
200
|
+
|
201
|
+
To report bugs with or suggest features/changes for Sifttter Redux, please use the [Issues Page](http://github.com/bachya/Sifttter-Redux/issues).
|
202
|
+
|
203
|
+
Contributions are welcome and encouraged. To contribute:
|
204
|
+
|
205
|
+
* [Fork Sifttter Redux](http://github.com/bachya/Sifttter-Redux/fork).
|
206
|
+
* Create a branch for your contribution (`git checkout -b new-feature`).
|
207
|
+
* Commit your changes (`git commit -am 'Added this new feature'`).
|
208
|
+
* Push to the branch (`git push origin new-feature`).
|
209
|
+
* Create a new [Pull Request](http://github.com/bachya/Sifttter-Redux/compare/).
|
210
|
+
|
211
|
+
## License
|
212
|
+
|
213
|
+
(The MIT License)
|
214
|
+
|
215
|
+
Copyright © 2014 Aaron Bach <bachya1208@gmail.com>
|
216
|
+
|
217
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
218
|
+
|
219
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
220
|
+
|
221
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
222
|
+
|
223
|
+
## Credits
|
224
|
+
|
225
|
+
* Craig Eley for Sifttter and for giving me the idea for Sifttter Redux
|
226
|
+
* Andrea Fabrizi for her stellar Dropbox Uploader project
|
227
|
+
* The Chronic folks for making the aforementioned wonderful Chronic gem
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
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
|
+
require 'rake/testtask'
|
39
|
+
Rake::TestTask.new do |t|
|
40
|
+
t.libs << "test"
|
41
|
+
t.test_files = FileList['test/*_test.rb']
|
42
|
+
end
|
43
|
+
|
44
|
+
task :default => [:test,:features]
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Ensure we require the local version and not one we might have installed already
|
2
|
+
require File.join([File.dirname(__FILE__),'lib','Sifttter-Redux','constants.rb'])
|
3
|
+
|
4
|
+
spec = Gem::Specification.new do |s|
|
5
|
+
s.name = 'sifttter-redux'
|
6
|
+
s.version = SifttterRedux::VERSION
|
7
|
+
s.author = 'Aaron Bach'
|
8
|
+
s.email = 'bachya1208@gmail.com'
|
9
|
+
s.homepage = 'https://github.com/bachya/Sifttter-Redux'
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.summary = 'Automated IFTTT to Day One engine.'
|
12
|
+
s.description = 'Sifttter Redux is a modification of Craig Eley\'s Sifttter that allows for smart installation on a standalone *NIX device (such as a Raspberry Pi).'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split($/)
|
15
|
+
s.test_files = `git ls-files -- test`.split($/)
|
16
|
+
s.require_paths << 'lib'
|
17
|
+
s.bindir = 'bin'
|
18
|
+
s.executables << 'srd'
|
19
|
+
|
20
|
+
s.license = 'MIT'
|
21
|
+
s.rdoc_options = ['--charset=UTF-8']
|
22
|
+
s.extra_rdoc_files = %w[README.md HISTORY.md LICENSE]
|
23
|
+
s.rdoc_options << '--title' << 'Sifttter-Redux' << '--main' << 'README.rdoc' << '-ri'
|
24
|
+
|
25
|
+
|
26
|
+
s.add_development_dependency('rake', '~> 0')
|
27
|
+
s.add_runtime_dependency('chronic', '0.10.2')
|
28
|
+
s.add_runtime_dependency('colored','1.2')
|
29
|
+
s.add_runtime_dependency('gli','2.9.0')
|
30
|
+
end
|
data/bin/srd
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#-------------------------------------------------------------------------------------------------------------
|
3
|
+
# Sifttter Redux
|
4
|
+
#
|
5
|
+
# A modification of Craig Eley's Sifttter that allows for smart installation on a standalone *NIX
|
6
|
+
# device (such as a Raspberry Pi).
|
7
|
+
#
|
8
|
+
# Sifttter copyright Craig Eley 2014 <http://craigeley.com>
|
9
|
+
#
|
10
|
+
# Copyright (c) 2014
|
11
|
+
# Aaron Bach <bachya1208@gmail.com>
|
12
|
+
#
|
13
|
+
# Permission is hereby granted, free of charge, to any person
|
14
|
+
# obtaining a copy of this software and associated documentation
|
15
|
+
# files (the "Software"), to deal in the Software without
|
16
|
+
# restriction, including without limitation the rights to use,
|
17
|
+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
18
|
+
# copies of the Software, and to permit persons to whom the
|
19
|
+
# Software is furnished to do so, subject to the following
|
20
|
+
# conditions:
|
21
|
+
#
|
22
|
+
# The above copyright notice and this permission notice shall be
|
23
|
+
# included in all copies or substantial portions of the Software.
|
24
|
+
#
|
25
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
26
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
27
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
28
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
29
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
30
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
31
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
32
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
33
|
+
#-------------------------------------------------------------------------------------------------------------
|
34
|
+
|
35
|
+
require 'colored'
|
36
|
+
require 'fileutils'
|
37
|
+
require 'gli'
|
38
|
+
require 'time'
|
39
|
+
require 'yaml'
|
40
|
+
|
41
|
+
require 'Sifttter-Redux'
|
42
|
+
|
43
|
+
include GLI::App
|
44
|
+
|
45
|
+
$config = ConfigManager.instance
|
46
|
+
$date_range_maker = DateRangeMaker.new
|
47
|
+
$db_uploader = File.join($config.db_uploader["local_filepath"], "dropbox_uploader.sh")
|
48
|
+
|
49
|
+
program_desc "Sifttter Redux
|
50
|
+
|
51
|
+
A modification of Craig Eley's Sifttter that allows for smart
|
52
|
+
installation on a standalone *NIX device (such as a Raspberry Pi)."
|
53
|
+
|
54
|
+
version SifttterRedux::VERSION
|
55
|
+
|
56
|
+
# desc 'Describe some switch here'
|
57
|
+
# switch [:s,:switch]
|
58
|
+
#
|
59
|
+
# desc 'Describe some flag here'
|
60
|
+
# default_value 'the default'
|
61
|
+
# arg_name 'The name of the argument'
|
62
|
+
# flag [:f,:flagname]
|
63
|
+
|
64
|
+
#| ======================================================
|
65
|
+
#| Pre, Post, and Error
|
66
|
+
#| ======================================================
|
67
|
+
|
68
|
+
pre do |global,command,options,args|
|
69
|
+
if !File.exists?(SifttterRedux::SRD_CONFIG_FILEPATH)
|
70
|
+
CliMessage.info("It doesn't look like you've initlized Sifttter Redux yet. Doing that now...")
|
71
|
+
initialize_procedures
|
72
|
+
end
|
73
|
+
true
|
74
|
+
end
|
75
|
+
|
76
|
+
post do |global,command,options,args|
|
77
|
+
# Post logic here
|
78
|
+
# Use skips_post before a command to skip this
|
79
|
+
# block on that command only
|
80
|
+
end
|
81
|
+
|
82
|
+
on_error do |exception|
|
83
|
+
# Error logic here
|
84
|
+
# return false to skip default error handling
|
85
|
+
true
|
86
|
+
end
|
87
|
+
|
88
|
+
#| ======================================================
|
89
|
+
#| Commands
|
90
|
+
#| ======================================================
|
91
|
+
|
92
|
+
#| ------------------------------------------------------
|
93
|
+
#| exec command
|
94
|
+
#|
|
95
|
+
#| Executes the script.
|
96
|
+
#| ------------------------------------------------------
|
97
|
+
|
98
|
+
desc 'Execute the script'
|
99
|
+
command :exec do |c|
|
100
|
+
|
101
|
+
c.flag(
|
102
|
+
[:f, :from],
|
103
|
+
:desc => 'Run catch-up mode with this start date',
|
104
|
+
)
|
105
|
+
|
106
|
+
c.flag(
|
107
|
+
[:t, :to],
|
108
|
+
:desc => 'Run catch-up mode with this end date (must be accompanied by --from)',
|
109
|
+
)
|
110
|
+
|
111
|
+
c.switch(
|
112
|
+
[:c, :last_7_days],
|
113
|
+
:desc => 'Run catch-up mode for the last 7 days'
|
114
|
+
)
|
115
|
+
|
116
|
+
c.switch(
|
117
|
+
[:i, :include_today],
|
118
|
+
:desc => 'Include today\'s date in catch-up'
|
119
|
+
)
|
120
|
+
|
121
|
+
c.switch(
|
122
|
+
[:y, :yesterday],
|
123
|
+
:desc => 'Run catch-up mode for yesterday'
|
124
|
+
)
|
125
|
+
|
126
|
+
c.action do |global_options, options, args|
|
127
|
+
command_complete = false
|
128
|
+
|
129
|
+
CliMessage.section('EXECUTING...')
|
130
|
+
|
131
|
+
if (options[:c] || options[:y] || options[:f] || options[:t])
|
132
|
+
if (!command_complete && options[:c])
|
133
|
+
dates = $date_range_maker.last_seven_days(options[:i])
|
134
|
+
command_complete = true
|
135
|
+
end
|
136
|
+
|
137
|
+
if (!command_complete && options[:y])
|
138
|
+
dates = $date_range_maker.yesterday
|
139
|
+
command_complete = true
|
140
|
+
end
|
141
|
+
|
142
|
+
if (!command_complete && (options[:f] || options[:t]))
|
143
|
+
begin
|
144
|
+
dates = $date_range_maker.range({
|
145
|
+
:start_date => options[:f],
|
146
|
+
:end_date => options[:t],
|
147
|
+
:include_today => options[:i],
|
148
|
+
})
|
149
|
+
|
150
|
+
if (dates.last > Date.today)
|
151
|
+
CliMessage.warning("Ignoring overextended end date and using today's date (#{Date.today})")
|
152
|
+
dates = (dates.first..Date.today)
|
153
|
+
end
|
154
|
+
rescue DateRangeMakerError
|
155
|
+
CliMessage.error($!)
|
156
|
+
end
|
157
|
+
command_complete = true
|
158
|
+
end
|
159
|
+
else
|
160
|
+
dates = $date_range_maker.today
|
161
|
+
command_complete = true
|
162
|
+
end
|
163
|
+
|
164
|
+
if (!dates.nil?)
|
165
|
+
CliMessage.info("Creating entries for dates from #{dates.first} to #{dates.reverse_each.first}...")
|
166
|
+
|
167
|
+
download_sifttter_files
|
168
|
+
|
169
|
+
dates.each do |date|
|
170
|
+
run_sifttter(date)
|
171
|
+
# puts date
|
172
|
+
end
|
173
|
+
# Upload any Day One entries to Dropbox (if there are any).
|
174
|
+
if (!Dir[$config.sifttter_redux["dayone_local_filepath"] + "/*"].empty?)
|
175
|
+
CliMessage.info("Uploading Day One entries to Dropbox...", false)
|
176
|
+
output = `#{$db_uploader} upload #{$config.sifttter_redux["dayone_local_filepath"] + "/*"} #{$config.sifttter_redux["dayone_remote_filepath"]}`
|
177
|
+
CliMessage.finish_message('DONE.')
|
178
|
+
end
|
179
|
+
|
180
|
+
# Remove any downloaded local files that we no longer need.
|
181
|
+
CliMessage.info("Removing downloaded Day One files...", false)
|
182
|
+
FileUtils.rm_rf($config.sifttter_redux["dayone_local_filepath"]) if Dir.exists?($config.sifttter_redux["dayone_local_filepath"])
|
183
|
+
CliMessage.finish_message('DONE.')
|
184
|
+
|
185
|
+
CliMessage.info("Removing downloaded Sifttter files...", false)
|
186
|
+
FileUtils.rm_rf($config.sifttter_redux["sifttter_local_filepath"]) if Dir.exists?($config.sifttter_redux["sifttter_local_filepath"])
|
187
|
+
CliMessage.finish_message('DONE.')
|
188
|
+
end
|
189
|
+
|
190
|
+
CliMessage.section('EXECUTION COMPLETE!')
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
#| ------------------------------------------------------
|
195
|
+
#| init command
|
196
|
+
#|
|
197
|
+
#| Initializes the script.
|
198
|
+
#| ------------------------------------------------------
|
199
|
+
desc 'Install and initialize dependencies'
|
200
|
+
command :init do |c|
|
201
|
+
c.action do |global_options, options, args|
|
202
|
+
CliMessage.section('INITIALIZING...')
|
203
|
+
|
204
|
+
if File.exists?($config.configFile)
|
205
|
+
initialize_procedures if CliMessage.prompt("It looks like you've already initialized Sifttter Redux. Do you want to re-initialize?", "N").downcase
|
206
|
+
else
|
207
|
+
initialize_procedures
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
exit run(ARGV)
|