rss_timeline 0.1.3 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 028b71dc8cf0fcaa3b625b5b79951a40b74579fd
4
- data.tar.gz: e63713b9b91aa3640e98ca5a2fae631a413e64dc
2
+ SHA256:
3
+ metadata.gz: 75d51049a865b301089684387077084461e29500cf515c51596b20efd0095d46
4
+ data.tar.gz: 9acc314a0929fbc6f0f28d58161d661bb694a8a13b64d617d76100a0c2958eb3
5
5
  SHA512:
6
- metadata.gz: 7663fc03601e0acbd205187edf4c123f66289f3d65a3e84836695eaf29b30e9158754bf2632f12a65bf825b36e482d5ce369aebd3b851d30ac9e1a06db46d63f
7
- data.tar.gz: 8fbb45a99dec66fd895e2a2aa0d5dfd2194f91304696114f85d65703230e1c25b29e9470d176a7f3243cd73963a7670e1c8d1bdf73471991dd5de024d5cdc4be
6
+ metadata.gz: 6761af952c7a0ec6b0aedf116ac7d9ec9875b49180d03bafafe65b3f5a3ff08fa9c2163f98b956eab51e32f525ecc79de987c808636a0626cef47a9c85dfd19c
7
+ data.tar.gz: ce41ce4e99fe7956af62bed1c3094217fff4f190374316117c4c0a08548afcdd64f327f491a661babfc7d8f17702e767a4fb408b37a1998fed2c41fe941ca75c
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/rss_timeline.rb CHANGED
@@ -9,130 +9,167 @@ require 'rss_creator'
9
9
 
10
10
 
11
11
  class RSStimeline
12
-
12
+
13
13
  attr_accessor :rssfile
14
14
 
15
- def initialize(feeds=[], rssfile: 'timeline.rss', xslt: nil)
15
+ def initialize(feeds=[], rssfile: 'timeline.rss', xslt: nil,
16
+ filepath: '.', debug: false, target_filepath: nil)
17
+
18
+ @source_feeds, @debug, @rssfile, @newupdate = feeds, debug, rssfile, false
19
+ @target_filepath = target_filepath
20
+
21
+ puts 'inside initialize' if @debug
16
22
 
17
- @source_feeds = feeds
23
+ @filepath = File.join(filepath, 'rss_timeline')
24
+ @cache_filepath = File.join(@filepath, 'cache')
18
25
 
19
- # create a cache directory if it doesn't alread exist
20
- FileUtils.mkdir_p 'cache'
26
+ # create a cache directory if it doesn't already exist
27
+ FileUtils.mkdir_p @cache_filepath
21
28
 
22
29
  if File.exists? rssfile then
23
30
  @timeline = RSScreator.new rssfile
24
31
  else
32
+
25
33
  @timeline = RSScreator.new
26
34
  self.title = 'My RSStimeline feed'
27
- self.description = 'Generated using the RSStimeline gem'
35
+ self.description = 'Generated using the RSStimeline gem'
36
+
28
37
  end
29
-
38
+
30
39
  @timeline.xslt = xslt if xslt
31
- @rssfile = rssfile
32
- @newupdate = false
40
+ puts '@timeline.xslt : ' + @timeline.xslt.inspect if @debug
33
41
 
34
42
  end
35
43
 
36
44
  def update()
37
45
 
38
46
  # fetch the feeds from the web
39
- feeds = @source_feeds.map {|feed| [feed, SimpleRSS.parse(open(feed))] }
47
+ feeds = @source_feeds.map {|feed| [feed, SimpleRSS.parse(URI.open(feed))] }
40
48
 
41
49
  # check for each feed from the cache.
42
50
  # if the feed is in the cache, compare the 2 to find any new items.
43
51
  # New items should be added to the main timeline RSS feed
44
52
 
53
+ updated = false
54
+
45
55
  feeds.each do |feed, rss|
46
56
 
47
- rssfile = File.join('cache', feed[6..-1].gsub(/\W+/,'').\
57
+ rssfile = File.join(@cache_filepath, feed[6..-1].gsub(/\W+/,'').\
48
58
  reverse.slice(0,40).reverse)
49
-
59
+
50
60
  if File.exists? rssfile then
51
61
 
52
62
  rss_cache = SimpleRSS.parse File.read(rssfile)
53
63
 
54
- new_rss_items = rss.items - rss_cache.items
64
+ fresh, old = [rss.items, rss_cache.items].map do |feed|
65
+ feed.clone.each {|x| x.delete :guid }
66
+ end
67
+
68
+
69
+ new_items = fresh - old
70
+
71
+ if @debug then
72
+ puts 'fresh: ' + fresh.inspect
73
+ puts 'old: ' + old.inspect
74
+ puts 'new_items: ' + new_items.inspect
75
+ end
76
+
77
+ new_rss_items = new_items.map do |x|
78
+ rss.items.find {|y| y[:title] == x[:title]}
79
+ end
80
+
55
81
  new_rss_items.reverse.each {|item| add_new item}
56
- File.write rssfile, rss.source if new_rss_items.any?
57
-
82
+
83
+ if new_rss_items.any? then
84
+ puts 'new_rss_items: ' + new_rss_items.inspect if @debug
85
+ updated = true
86
+ File.write rssfile, rss.source
87
+ end
88
+
58
89
  else
59
90
 
91
+ updated = true
60
92
  add_new rss.items.first
61
93
  File.write rssfile, rss.source
62
-
94
+
63
95
  end
64
96
  end
65
-
66
- save()
67
-
97
+
98
+ save() if updated
99
+
68
100
  end
69
-
101
+
70
102
  def description()
71
103
  @timeline.description
72
104
  end
73
-
105
+
74
106
  def description=(val)
75
107
  @timeline.description = val
76
108
  end
77
-
109
+
78
110
  def link(val)
79
111
  @timeline.link
80
112
  end
81
-
113
+
82
114
  def link=(val)
83
115
  @timeline = val
84
116
  end
85
-
117
+
86
118
  def title()
87
119
  @timeline.title
88
120
  end
89
-
121
+
90
122
  def title=(val)
91
123
  @timeline.title = val
92
124
  end
93
-
125
+
94
126
  protected
95
-
127
+
96
128
  def on_new_item(item)
97
- # you can override this method to create your
129
+ # you can override this method to create your
98
130
  # own notifier, callback, or webhook
99
131
  end
100
-
132
+
101
133
  def on_update()
102
- # you can override this method to create your
134
+ # you can override this method to create your
103
135
  # own notifier, callback, or webhook
104
- end
105
-
136
+ end
137
+
106
138
  private
107
-
139
+
108
140
  def add_new(item)
109
-
110
- @timeline.add new_item(item), id: nil
141
+
142
+ puts 'inside add_new: ' + item.inspect if @debug
143
+
144
+ @timeline.add item: new_item(item), id: nil
111
145
  @newupdate = true
112
146
  on_new_item(item)
113
-
147
+
114
148
  end
115
-
149
+
116
150
  def new_item(x)
117
-
118
- {
119
- title: x[:title],
120
- link: x[:link],
121
- description: x[:description],
151
+
152
+ h = {
153
+ title: x[:title],
154
+ link: x[:link],
155
+ description: x[:description],
122
156
  date: x[:date] || Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")
123
157
  }
124
-
158
+
159
+ puts 'inside new_item: ' + h.inspect if @debug
160
+
161
+ h
162
+
125
163
  end
126
-
164
+
127
165
  def save()
128
-
129
- return unless @newupdate
130
-
131
- on_update()
166
+
132
167
  @newupdate = false
133
-
134
- @timeline.save @rssfile
135
-
168
+
169
+ @timeline.save File.join(@filepath, @rssfile)
170
+ @timeline.save File.join(@target_filepath, @rssfile) if @target_filepath
171
+ on_update()
172
+
136
173
  end
137
-
138
- end
174
+
175
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rss_timeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,28 +10,32 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
- YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTE1MTAyNTEyNDAyN1oXDTE2MTAyNDEyNDAyN1owSDESMBAG
16
- A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
- EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
- ggEBANvq4jalaj3tw/5HHNB70rlQ+bcsYzzoq+wMTnB01er3a2GwVTxpHFZdRL/8
19
- BnR6jg/3ekbC4rLs7hNw8BJR0Kl0J0t00tbljSk9lDDO5sylF0lB8AxL1aM9xbXa
20
- fvdYNi05ePRFCU/HcaFUrebJENX6WGey8460sJU+MRxxuDJRZ4UNyUyrGXDzP8x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Hoo
33
+ uT7Xa9HSWeV7zMgohnPRGVbF+r2yPsVUXPZmb+coXUV4WHsCLypaDojqCanNouyo
34
+ uV5AKfB2wO57X83nRdJ8OzrUzCZVxYX3WpTbUIn/n0k4h7CoCRinO/wUM9aCEuyL
35
+ 9TjZeJfzvcT9qoVK2mzNoDK6P7AL4m7kfnLfQUIc2aF5x9/zIcBi5tEMDcnujsKH
36
+ l5hjs/75OfrhM2lNdizSwpSW
33
37
  -----END CERTIFICATE-----
34
- date: 2015-11-14 00:00:00.000000000 Z
38
+ date: 2021-11-18 00:00:00.000000000 Z
35
39
  dependencies:
36
40
  - !ruby/object:Gem::Dependency
37
41
  name: simple-rss
@@ -42,7 +46,7 @@ dependencies:
42
46
  version: '1.3'
43
47
  - - ">="
44
48
  - !ruby/object:Gem::Version
45
- version: 1.3.1
49
+ version: 1.3.3
46
50
  type: :runtime
47
51
  prerelease: false
48
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -52,29 +56,29 @@ dependencies:
52
56
  version: '1.3'
53
57
  - - ">="
54
58
  - !ruby/object:Gem::Version
55
- version: 1.3.1
59
+ version: 1.3.3
56
60
  - !ruby/object:Gem::Dependency
57
61
  name: rss_creator
58
62
  requirement: !ruby/object:Gem::Requirement
59
63
  requirements:
60
64
  - - "~>"
61
65
  - !ruby/object:Gem::Version
62
- version: '0.2'
66
+ version: '0.4'
63
67
  - - ">="
64
68
  - !ruby/object:Gem::Version
65
- version: 0.2.3
69
+ version: 0.4.2
66
70
  type: :runtime
67
71
  prerelease: false
68
72
  version_requirements: !ruby/object:Gem::Requirement
69
73
  requirements:
70
74
  - - "~>"
71
75
  - !ruby/object:Gem::Version
72
- version: '0.2'
76
+ version: '0.4'
73
77
  - - ">="
74
78
  - !ruby/object:Gem::Version
75
- version: 0.2.3
79
+ version: 0.4.2
76
80
  description:
77
- email: james@r0bertson.co.uk
81
+ email: digital.robertson@gmail.com
78
82
  executables: []
79
83
  extensions: []
80
84
  extra_rdoc_files: []
@@ -100,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
104
  version: '0'
101
105
  requirements: []
102
106
  rubyforge_project:
103
- rubygems_version: 2.4.8
107
+ rubygems_version: 2.7.10
104
108
  signing_key:
105
109
  specification_version: 4
106
110
  summary: An RSS aggregator which generates an RSS file
metadata.gz.sig CHANGED
Binary file