sifttter-redux 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,188 +0,0 @@
1
- #| ======================================================
2
- #| METHODS
3
- #| ======================================================
4
-
5
- #| ------------------------------------------------------
6
- #| collect_preferences method
7
- #|
8
- #| Collects preferences from the user and stores the
9
- #| entered values into a configuration file.
10
- #| @return Void
11
- #| ------------------------------------------------------
12
- def collect_preferences
13
- CliMessage.section('COLLECTING PREFERENCES...')
14
-
15
- pref = CliMessage.prompt("Location for downloaded Sifttter files from Dropbox", SifttterRedux::SFT_LOCAL_FILEPATH)
16
- $config.add_to_section({"sifttter_local_filepath" => pref}, "sifttter_redux")
17
-
18
- pref = CliMessage.prompt("Location of Sifttter files in Dropbox", SifttterRedux::SFT_REMOTE_FILEPATH)
19
- $config.add_to_section({"sifttter_remote_filepath" => pref}, "sifttter_redux")
20
-
21
- pref = CliMessage.prompt("Location for downloaded Day One files from Dropbox", SifttterRedux::DO_LOCAL_FILEPATH)
22
- $config.add_to_section({"dayone_local_filepath" => pref}, "sifttter_redux")
23
-
24
- pref = CliMessage.prompt("Location of Day One files in Dropbox", SifttterRedux::DO_REMOTE_FILEPATH)
25
- $config.add_to_section({"dayone_remote_filepath" => pref}, "sifttter_redux")
26
- end
27
-
28
- #| ------------------------------------------------------
29
- #| download_sifttter_files method
30
- #|
31
- #| Downloads Sifttter files from Dropbox
32
- #| @return Void
33
- #| ------------------------------------------------------
34
- def download_sifttter_files
35
- # Download all Sifttter files from Dropbox.
36
- CliMessage.info('Downloading Sifttter files...', false)
37
- `#{$db_uploader} download #{$config.sifttter_redux["sifttter_remote_filepath"]} #{$config.sifttter_redux["sifttter_local_filepath"]}`
38
- CliMessage.finish_message('DONE.')
39
- end
40
-
41
- #| ------------------------------------------------------
42
- #| initialize_procedures method
43
- #|
44
- #| Initializes Sifttter Redux by downloading and collecting
45
- #| all necessary items and info.
46
- #| @return Void
47
- #| ------------------------------------------------------
48
- def initialize_procedures
49
- $config.reset
50
- $config.create_section("sifttter_redux")
51
- $config.add_to_section({"config_location" => $config.configFile}, "sifttter_redux")
52
-
53
- install_db_uploader
54
- collect_preferences
55
-
56
- $config.save_configuration
57
- end
58
-
59
- #| ------------------------------------------------------
60
- #| install_db_uploader method
61
- #|
62
- #| Installs Dropbox Uploader to a user-specified location
63
- #| by cloning the git repository.
64
- #| @return Void
65
- #| ------------------------------------------------------
66
- def install_db_uploader
67
- valid_directory_chosen = false
68
-
69
- CliMessage.section('CONFIGURING DROPBOX UPLOADER...')
70
-
71
- # Create a new configuration section for Dropbox-Uploader
72
- $config.create_section("db_uploader")
73
-
74
- until valid_directory_chosen
75
- # Prompt the user for a location to save Dropbox Uploader. "
76
- db_uploader_location = CliMessage.prompt("Location for Dropbox-Uploader", SifttterRedux::DBU_LOCAL_FILEPATH)
77
- db_uploader_location.chop! if db_uploader_location.end_with?('/')
78
- db_uploader_location = "/usr/local/opt" if db_uploader_location.empty?
79
-
80
- # If the entered directory exists, clone the repository.
81
- if File.directory?(db_uploader_location)
82
- valid_directory_chosen = true
83
- db_uploader_location << "/Dropbox-Uploader"
84
-
85
- # If, for some reason, Dropbox Uploader alread exists at this location,
86
- # skip the clone.
87
- if File.directory?(db_uploader_location)
88
- CliMessage.warning("Using pre-existing Dropbox Uploader at #{db_uploader_location}...")
89
- else
90
- CliMessage.info("Downloading Dropbox Uploader to #{db_uploader_location}...")
91
- %x{git clone https://github.com/andreafabrizi/Dropbox-Uploader.git #{db_uploader_location}}
92
- end
93
-
94
- # Save config data to YAML.
95
- $config.add_to_section({"local_filepath" => db_uploader_location}, "db_uploader")
96
- else
97
- puts "Sorry, but #{db_uploader_location} isn't a valid directory."
98
- end
99
- end
100
- end
101
-
102
- #| ------------------------------------------------------
103
- #| run_sifttter method
104
- #|
105
- #| Modified form of Sifttter
106
- #|
107
- #| Sifttter: An IFTTT-to-Day One Logger by Craig Eley 2014
108
- #| Based on tp-dailylog.rb by Brett Terpstra 2012
109
- #| @param date The date to use when scanning Sifttter files
110
- #| @return Void
111
- #| ------------------------------------------------------
112
- def run_sifttter(date)
113
- uuid_command = "uuidgen" if OS.mac?
114
- uuid_command = "uuid" if OS.linux?
115
- uuid = %x{#{uuid_command}}.gsub(/-/,'').strip
116
-
117
- date_for_title = date.strftime('%B %d, %Y')
118
- datestamp = date.to_time.utc.iso8601
119
- starred = false
120
-
121
- template = ERB.new <<-XMLTEMPLATE
122
- <?xml version="1.0" encoding="UTF-8"?>
123
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
124
- <plist version="1.0">
125
- <dict>
126
- <key>Creation Date</key>
127
- <date><%= datestamp %></date>
128
- <key>Entry Text</key>
129
- <string><%= entrytext %></string>
130
- <key>Starred</key>
131
- <<%= starred %>/>
132
- <key>Tags</key>
133
- <array>
134
- <string>daily logs</string>
135
- </array>
136
- <key>UUID</key>
137
- <string><%= uuid %></string>
138
- </dict>
139
- </plist>
140
- XMLTEMPLATE
141
-
142
- date_regex = "#{date.strftime('%B')} 0?#{date.strftime('%-d')}, #{date.strftime('%Y')}"
143
- time_regex = "\d{1,2}:\d{1,2}\s?[AaPpMm]{2}"
144
-
145
- files = %x{find #{$config.sifttter_redux["sifttter_local_filepath"]} -type f -name '*.txt' | grep -v -i daily | sort}
146
-
147
- projects = []
148
- files.split("\n").each do |file|
149
- if File.exists?(file.strip)
150
- f = File.open(file.strip, encoding: 'UTF-8')
151
- lines = f.read
152
- f.close
153
- project = "### " + File.basename(file).gsub(/^.*?\/([^\/]+)$/,"\\1") + "\n"
154
-
155
- found_completed = false
156
- lines.each_line do |line|
157
- if line =~ /&/
158
- line.gsub!(/[&]/, 'and')
159
- end
160
- if line =~ /#{date_regex}/
161
- found_completed = true
162
- project += line.gsub(/@done/,'').gsub(/#{date_regex}\s(-|at)\s/, '').gsub(/#{time_regex}\s-\s/, '').strip + "\n"
163
- end
164
- end
165
- end
166
- if found_completed
167
- projects.push(project)
168
- end
169
- end
170
-
171
- if projects.length <=0
172
- CliMessage.warning("No entries found...")
173
- end
174
-
175
- if projects.length > 0
176
- entrytext = "# Things done on #{date_for_title}\n\n"
177
- projects.each do |project|
178
- entrytext += project.gsub(/.txt/, ' ') + "\n\n"
179
- end
180
-
181
- Dir.mkdir($config.sifttter_redux["dayone_local_filepath"]) if !Dir.exists?($config.sifttter_redux["dayone_local_filepath"])
182
-
183
- fh = File.new(File.expand_path($config.sifttter_redux["dayone_local_filepath"] + "/" + uuid + ".doentry"), 'w+')
184
- fh.puts template.result(binding)
185
- fh.close
186
- CliMessage.success("Entry logged for #{date_for_title}...")
187
- end
188
- end
@@ -1,47 +0,0 @@
1
- #| ======================================================
2
- #| OS Module
3
- #|
4
- #| Module to easily find the running operating system
5
- #| ======================================================
6
- module OS
7
-
8
- #| ------------------------------------------------------
9
- #| linux? method
10
- #|
11
- #| Returns true if the host OS is Linux (false otherwise).
12
- #| @return Bool
13
- #| ------------------------------------------------------
14
- def OS.linux?
15
- OS.unix? and not OS.mac?
16
- end
17
-
18
- #| ------------------------------------------------------
19
- #| mac? method
20
- #|
21
- #| Returns true if the host OS is OS X (false otherwise).
22
- #| @return Bool
23
- #| ------------------------------------------------------
24
- def OS.mac?
25
- (/darwin/ =~ RUBY_PLATFORM) != nil
26
- end
27
-
28
- #| ------------------------------------------------------
29
- #| unix? method
30
- #|
31
- #| Returns true if the host OS is Unix (false otherwise).
32
- #| @return Bool
33
- #| ------------------------------------------------------
34
- def OS.unix?
35
- !OS.windows?
36
- end
37
-
38
- #| ------------------------------------------------------
39
- #| windows? method
40
- #|
41
- #| Returns true if the host OS is Windows (false otherwise).
42
- #| @return Bool
43
- #| ------------------------------------------------------
44
- def OS.windows?
45
- (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
46
- end
47
- end