Module: SifttterRedux::Sifttter

Defined in:
lib/sifttter-redux/sifttter.rb

Overview

Sifttter Module Wrapper module for Sifttter itself

Class Method Summary collapse

Class Method Details

.run(date) ⇒ void

This method returns an undefined value.

Sifttter: An IFTTT-to-Day One Logger by Craig Eley Based on tp-dailylog.rb by Brett Terpstra 2012

Parameters:

  • date (Date)

    The date to use when scanning Sifttter



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/sifttter-redux/sifttter.rb', line 9

def self.run(date)
  uuid = SecureRandom.uuid.upcase.gsub(/-/, '').strip

  date_for_title = date.strftime('%B %d, %Y')
  datestamp = date.to_time.utc.iso8601
  starred = false

  template = ERB.new "  <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n  <!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n  <plist version=\"1.0\">\n  <dict>\n    <key>Creation Date</key>\n    <date><%= datestamp %></date>\n    <key>Entry Text</key>\n    <string><%= entrytext %></string>\n    <key>Starred</key>\n    <<%= starred %>/>\n    <key>Tags</key>\n    <array>\n      <string>daily logs</string>\n    </array>\n    <key>UUID</key>\n    <string><%= uuid %></string>\n  </dict>\n  </plist>\n  XMLTEMPLATE\n\n  date_regex = \"(?:\#{ date.strftime(\"%B\") } 0?\#{ date.strftime(\"%-d\") }, \#{ date.strftime(\"%Y\") })\"\n  time_regex = \"(?:\\d{1,2}:\\d{1,2}\\s?[AaPpMm]{2})\"\n\n  files = `find \#{ configuration.sifttter_redux[:sifttter_local_filepath] } -type f -name \"*.txt\" | grep -v -i daily | sort`\n  if files.empty?\n    messenger.error('No Sifttter files to parse...')\n    messenger.error('Is Dropbox Uploader configured correctly?')\n    messenger.error(\"Is \#{ configuration.sifttter_redux[:sifttter_remote_filepath] } the correct remote filepath?\")\n    exit!(1)\n  end\n\n  projects = []\n  files.split(\"\\n\").each do |file|\n    if File.exists?(file.strip)\n      f = File.open(file.strip, encoding: 'UTF-8')\n      lines = f.read\n      f.close\n      project = '### ' + File.basename(file).gsub(/^.*?\\/([^\\/]+)$/, \"\\\\1\") + \"\\n\"\n\n      found_completed = false\n      lines.each_line do |line|\n        if line =~ /&/\n          line.gsub!(/[&]/, 'and')\n        end\n        if line =~ /\#{ date_regex }/\n          found_completed = true\n          project += line.gsub(/@done/,\"\").gsub(/\#{ date_regex }\\s(-|at)\\s/, \"\").gsub(/\#{ time_regex }\\s-\\s/, \"\").strip + \"\\n\"\n        end\n      end\n    end\n    if found_completed\n      projects.push(project)\n    end\n  end\n\n  if projects.length <=0\n    messenger.warn('No entries found...')\n  end\n\n  if projects.length > 0\n    entrytext = \"# Things done on \#{ date_for_title }\\n\\n\"\n    projects.each do |project|\n      entrytext += project.gsub(/.txt/, ' ') + \"\\n\\n\"\n    end\n\n    Dir.mkdir(configuration.sifttter_redux[:dayone_local_filepath]) if !Dir.exists?(configuration.sifttter_redux[:dayone_local_filepath])\n\n    fh = File.new(File.expand_path(configuration.sifttter_redux[:dayone_local_filepath] + '/' + uuid + '.doentry'), 'w+')\n    fh.puts template.result(binding)\n    fh.close\n    messenger.success(\"Entry logged for \#{ date_for_title }...\")\n  end\nend\n"