trackchange 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -46,6 +46,44 @@ Or install it yourself as:
46
46
  trackchange uninstall
47
47
 
48
48
 
49
+ ## Configuration
50
+
51
+ Trackchange creates its configuration file in `~/.trackchange/config.yml`.
52
+
53
+ ### fetch
54
+
55
+ This is the command to fetch the tracked sites. `%url%` will be
56
+ substituted by the requested site url.
57
+
58
+ The default command is
59
+
60
+ lynx -dump '%url%' | uniq
61
+
62
+ Here are some alternatives you might want to experiment
63
+ with. (Unfortunately pandoc only works with http, not with https and
64
+ does not follow redirects, hence the version with curl.)
65
+
66
+ lynx -dump '%url%' | uniq | sed -e "/References/,/\s+[0-9]+\. h/d"
67
+
68
+ pandoc '%url%' -t markdown
69
+
70
+ pandoc '%url%' -t plain
71
+
72
+ curl -sL '%url%' | pandoc -t plain
73
+
74
+ ### rss_path
75
+
76
+ ...
77
+
78
+ ### feed_size
79
+
80
+ ...
81
+
82
+ ### log_level
83
+
84
+ ...
85
+
86
+
49
87
  ## Contributing
50
88
 
51
89
  1. Fork it
@@ -87,7 +87,7 @@ module Trackchange
87
87
 
88
88
  # upgrade from <= 0.2.0
89
89
  if v(data[:version]) <= v('0.2.0')
90
- data[:version] = VERSION
90
+ data[:version] = '0.2.0'
91
91
  data[:sites] = data[:sites].map do |site|
92
92
  { url: site }
93
93
  end
@@ -95,6 +95,15 @@ module Trackchange
95
95
  store_config!
96
96
  end
97
97
 
98
+ # upgrade from 0.3.0 to 0.4.0
99
+ if v(data[:version]) < v('0.4.0')
100
+ data[:version ] = '0.4.0'
101
+ data[:fetch] = "lynx -dump '%url%' | uniq"
102
+ data[:feed_size] = 20
103
+ @config = OpenStruct.new(data)
104
+ store_config!
105
+ end
106
+
98
107
  @config = OpenStruct.new(data)
99
108
  end
100
109
 
@@ -20,9 +20,9 @@ module Trackchange
20
20
  url = site[:url]
21
21
  fname = url.sub(%r{https?://}, '').tr_s('/?&', '...')
22
22
  site_path = File.expand_path(fname, '~/.trackchange')
23
- lynx = "lynx -dump '#{url}' | uniq > #{site_path}.new"
24
- logger.debug "% #{lynx}"
25
- system lynx
23
+ cmd = config.fetch.gsub('%url%', url) + "> #{site_path}.new"
24
+ logger.debug "% #{cmd}"
25
+ system cmd
26
26
 
27
27
  unless File.exist?(site_path) # new site
28
28
  logger.warn "new site #{url}"
@@ -75,8 +75,47 @@ module Trackchange
75
75
  end
76
76
  end
77
77
 
78
- if rss_path = config.rss_path # write rss
79
- logger.info "update feed #{rss_path} (not realy, yet)"
78
+ if file = File.expand_path(config.rss_path, ENV['HOME']) # write rss
79
+ logger.info "update rss feed '#{file}'"
80
+
81
+ out_rss = RSS::Maker.make('1.0') do |maker|
82
+ maker.channel.id = %x[ whoami ].chomp
83
+ maker.channel.author = %x[ whoami ].chomp
84
+ maker.channel.updated = Time.now.to_s
85
+ maker.channel.title = "Trackchange"
86
+ maker.channel.link = "http://github.com/brnach14/trackchange"
87
+ maker.channel.about = "Feed of detected changes"
88
+ maker.channel.description = "Feed of detected changes"
89
+
90
+ # new item
91
+ maker.items.new_item do |item|
92
+ item.link = "#{url}##{Time.now.to_i}"
93
+ item.title = "Change detected on #{url}"
94
+ item.date = Time.now.to_s
95
+ item.description = "<pre>#{result}</pre>"
96
+ end
97
+
98
+ # read rss, keepn old items
99
+ if File.exist?(file)
100
+ in_rss = RSS::Parser.parse(File.read(file))
101
+ in_rss.items.each_with_index do |in_item, index|
102
+ break if index > config.feed_size - 1
103
+ maker.items.new_item do |out_item|
104
+ out_item.link = in_item.link
105
+ out_item.title = in_item.title
106
+ out_item.date = in_item.date
107
+ out_item.description = in_item.description
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ # write rss
114
+ if File.exist?(file) and !File.writable?(file)
115
+ raise "'#{file}' is not writable, skipping rss persistency"
116
+ else
117
+ File.open(file, 'w') { |f| f.puts(out_rss) }
118
+ end
80
119
  end
81
120
  end
82
121
 
@@ -84,6 +123,9 @@ module Trackchange
84
123
  return @logger if @logger
85
124
  @logger = Logger.new(STDOUT).tap do |logger|
86
125
  logger.level = (config.log_level || 2).to_i
126
+ logger.formatter = proc do |severity, datetime, progname, msg|
127
+ "#{msg}\n"
128
+ end
87
129
  end
88
130
  end
89
131
 
@@ -1,3 +1,3 @@
1
1
  module Trackchange
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trackchange
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-22 00:00:00.000000000 Z
12
+ date: 2015-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cronedit
@@ -94,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  segments:
96
96
  - 0
97
- hash: -4153791099187356125
97
+ hash: 4114028559978867129
98
98
  required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  none: false
100
100
  requirements:
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  segments:
105
105
  - 0
106
- hash: -4153791099187356125
106
+ hash: 4114028559978867129
107
107
  requirements: []
108
108
  rubyforge_project:
109
109
  rubygems_version: 1.8.23