rss_timeline 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d9ef3c897983856ec364cdccb3292e423fd85ee
4
- data.tar.gz: 31612b7ff8e986e2dbadaa1fee7547a7ec6f4371
3
+ metadata.gz: 639253db51c59a5e10d6a2303e5f02ec4cac55db
4
+ data.tar.gz: 24151e07742f8b43931bf2ef735d11dcc492b3ab
5
5
  SHA512:
6
- metadata.gz: 462205305835b1486af6181a76acb98df75abdb10c47d11b28faf881235ab14ec3ca1c0ea5d566c67b713fe05a068f0ef0be329a4038abf32156ea46a67a652f
7
- data.tar.gz: 3d128d42f77e7ec71dc5eb06b58914b2e016ae934aeaa3c6263f91e4a5337d6a8249322e66ec3a3e881cb019d13ab0d3f7ebf464f426a8d0ca527e925e2aa9b7
6
+ metadata.gz: e3ada7acf96385bd7d4d693bce9d40bfa07b26107119649c4f9c36bda8149ec8b18427adfb4d07d359f080de05c23f53cfdcb53fa54a43737071ceaad799a8c9
7
+ data.tar.gz: 2b58f0f1387eaa709fc4ec345916e82818055053a0e436f70c4649d33ab0a2ca197e0946c391424dba05777d41647211850ecef6708985b5444629c670340e4c
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -12,27 +12,32 @@ 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)
16
17
 
17
- puts 'inside initialize'
18
+ @source_feeds, @debug, @rssfile, @newupdate = feeds, debug, rssfile, false
19
+ @target_filepath = target_filepath
18
20
 
19
- @source_feeds = feeds
21
+ puts 'inside initialize' if @debug
20
22
 
21
- # create a cache directory if it doesn't alread exist
22
- FileUtils.mkdir_p 'cache'
23
+ @filepath = File.join(filepath, 'rss_timeline')
24
+ @cache_filepath = File.join(@filepath, 'cache')
25
+
26
+ # create a cache directory if it doesn't already exist
27
+ FileUtils.mkdir_p @cache_filepath
23
28
 
24
29
  if File.exists? rssfile then
25
- @timeline = RSScreator.new rssfile
26
- else
27
- @timeline = RSScreator.new
30
+ @timeline =RSScreator.new rssfile
31
+ else
32
+
33
+ @timeline =RSScreator.new
28
34
  self.title = 'My RSStimeline feed'
29
- self.description = 'Generated using the RSStimeline gem'
35
+ self.description = 'Generated using the RSStimeline gem'
36
+
30
37
  end
31
38
 
32
39
  @timeline.xslt = xslt if xslt
33
- puts '@timeline.xslt : ' + @timeline.xslt.inspect
34
- @rssfile = rssfile
35
- @newupdate = false
40
+ puts '@timeline.xslt : ' + @timeline.xslt.inspect if @debug
36
41
 
37
42
  end
38
43
 
@@ -44,29 +49,46 @@ class RSStimeline
44
49
  # check for each feed from the cache.
45
50
  # if the feed is in the cache, compare the 2 to find any new items.
46
51
  # New items should be added to the main timeline RSS feed
52
+
53
+ updated = false
47
54
 
48
55
  feeds.each do |feed, rss|
49
56
 
50
- rssfile = File.join('cache', feed[6..-1].gsub(/\W+/,'').\
57
+ rssfile = File.join(@cache_filepath, feed[6..-1].gsub(/\W+/,'').\
51
58
  reverse.slice(0,40).reverse)
52
59
 
53
60
  if File.exists? rssfile then
54
61
 
55
62
  rss_cache = SimpleRSS.parse File.read(rssfile)
56
63
 
57
- 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
+ new_items = fresh - old
69
+
70
+ new_rss_items = new_items.map do |x|
71
+ rss.items.find {|y| y[:title] == x[:title]}
72
+ end
73
+
58
74
  new_rss_items.reverse.each {|item| add_new item}
59
- File.write rssfile, rss.source if new_rss_items.any?
75
+
76
+ if new_rss_items.any? then
77
+ puts 'new_rss_items: ' + new_rss_items.inspect if @debug
78
+ updated = true
79
+ File.write rssfile, rss.source
80
+ end
60
81
 
61
82
  else
62
83
 
84
+ updated = true
63
85
  add_new rss.items.first
64
86
  File.write rssfile, rss.source
65
87
 
66
88
  end
67
89
  end
68
90
 
69
- save()
91
+ save() if updated
70
92
 
71
93
  end
72
94
 
@@ -110,6 +132,8 @@ class RSStimeline
110
132
 
111
133
  def add_new(item)
112
134
 
135
+ puts 'inside add_new: ' + item.inspect if @debug
136
+
113
137
  @timeline.add item: new_item(item), id: nil
114
138
  @newupdate = true
115
139
  on_new_item(item)
@@ -118,13 +142,17 @@ class RSStimeline
118
142
 
119
143
  def new_item(x)
120
144
 
121
- {
145
+ h = {
122
146
  title: x[:title],
123
147
  link: x[:link],
124
148
  description: x[:description],
125
149
  date: x[:date] || Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")
126
150
  }
127
151
 
152
+ puts 'inside new_item: ' + h.inspect if @debug
153
+
154
+ h
155
+
128
156
  end
129
157
 
130
158
  def save()
@@ -134,7 +162,8 @@ class RSStimeline
134
162
  on_update()
135
163
  @newupdate = false
136
164
 
137
- @timeline.save @rssfile
165
+ @timeline.save File.join(@filepath, @rssfile)
166
+ @timeline.save File.join(@target_filepath, @rssfile) if @target_filepath
138
167
 
139
168
  end
140
169
 
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.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  UtkkA/5alscVe1rFL0gDY+bBheYVtTWDEkNYn8lwqtRp0d/fWsXUFg5d5BvTCrF+
32
32
  FZcCmMq+Tfz/tQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2017-03-14 00:00:00.000000000 Z
34
+ date: 2018-02-03 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: simple-rss
@@ -59,20 +59,20 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '0.2'
62
+ version: '0.3'
63
63
  - - ">="
64
64
  - !ruby/object:Gem::Version
65
- version: 0.2.3
65
+ version: 0.3.11
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - "~>"
71
71
  - !ruby/object:Gem::Version
72
- version: '0.2'
72
+ version: '0.3'
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.2.3
75
+ version: 0.3.11
76
76
  description:
77
77
  email: james@jamesrobertson.eu
78
78
  executables: []
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.6.8
103
+ rubygems_version: 2.6.13
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: An RSS aggregator which generates an RSS file
metadata.gz.sig CHANGED
Binary file