pluto 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/pluto/updater.rb CHANGED
@@ -4,246 +4,31 @@ class Updater
4
4
 
5
5
  include LogUtils::Logging
6
6
 
7
- include Models
8
-
9
- def initialize
10
- @worker = ::Fetcher::Worker.new
11
- end
12
-
13
- attr_reader :worker
14
-
15
- def debug=(value)
16
- @debug = value
17
- ### logger.debug "[Updater] setting debug flag - debug? #{debug?}"
18
- end
19
-
20
- def debug?
21
- @debug || false
7
+ def initialize( opts, config )
8
+ @opts = opts
9
+ @config = config
22
10
  end
23
11
 
24
- def fetch_feed( url )
25
-
26
- ### fix: use worker.get( url ) # check http response code etc.
27
-
28
- xml = worker.read( url )
29
-
30
- ###
31
- # NB: Net::HTTP will NOT set encoding UTF-8 etc.
32
- # will mostly be ASCII
33
- # - try to change encoding to UTF-8 ourselves
34
- logger.debug "xml.encoding.name (before): #{xml.encoding.name}"
35
-
36
- #####
37
- # NB: ASCII-8BIT == BINARY == Encoding Unknown; Raw Bytes Here
38
-
39
- ## NB:
40
- # for now "hardcoded" to utf8 - what else can we do?
41
- # - note: force_encoding will NOT change the chars only change the assumed encoding w/o translation
42
- xml = xml.force_encoding( Encoding::UTF_8 )
43
- logger.debug "xml.encoding.name (after): #{xml.encoding.name}"
44
- xml
45
- end
46
-
47
-
48
- def update_subscriptions( config, opts={} )
49
-
50
- ## for now - use single site w/ key planet -- fix!! allow multiple sites (planets)
51
-
52
- site_attribs = {
53
- title: config[ 'title' ]
54
- }
55
-
56
- site_key = 'planet'
57
- site_rec = Site.find_by_key( site_key )
58
- if site_rec.nil?
59
- site_rec = Site.new
60
- site_attribs[ :key ] = site_key
61
-
62
- ## use object_id: site.id and object_type: Site
63
- ## change - model/table/schema!!!
64
- Action.create!( title: 'new site', object: site_attribs[ :title ] )
65
- end
66
- site_rec.update_attributes!( site_attribs )
67
-
68
- # -- log update action
69
- Action.create!( title: 'update subscriptions' )
70
-
71
-
72
- config.each do |key, value|
73
-
74
- next if ['title','feeds'].include?( key ) # skip "top-level" feed keys e.g. title, etc.
75
-
76
- ### todo/check:
77
- ## check value - must be hash
78
- # check if url or feed_url present
79
- # that is, check for required props/key-value pairs
80
-
81
- feed_key = key.to_s.dup
82
- feed_hash = value
83
-
84
- feed_attribs = {
85
- feed_url: feed_hash[ 'feed_url' ],
86
- url: feed_hash[ 'url' ],
87
- title: feed_hash[ 'title' ] # todo: use title from feed?
88
- }
89
-
90
- puts "Updating feed subscription >#{feed_key}< - >#{feed_attribs[:feed_url]}<..."
91
-
92
- feed_rec = Feed.find_by_key( feed_key )
93
- if feed_rec.nil?
94
- feed_rec = Feed.new
95
- feed_attribs[ :key ] = feed_key
96
-
97
- ## use object_id: feed.id and object_type: Feed
98
- ## change - model/table/schema!!!
99
- ## todo: add parent_action_id - why? why not?
100
- Action.create!( title: 'new feed', object: feed_attribs[ :title ] )
101
- end
102
-
103
- feed_rec.update_attributes!( feed_attribs )
104
-
105
- ## todo:
106
- # add subscription records (feed,site) - how?
107
- end
108
-
109
- end # method update_subscriptions
110
-
111
-
112
- def update_feeds( opts={} )
113
-
114
- if debug?
115
- ## turn on logging for sql too
116
- ActiveRecord::Base.logger = Logger.new( STDOUT )
117
- end
118
-
119
- ### move to feedutils
120
- ### logger.debug "using stdlib RSS::VERSION #{RSS::VERSION}"
121
-
122
- # -- log update action
123
- Action.create!( title: 'update feeds' )
124
-
125
- #####
126
- # -- update fetched_at timestamps for all sites
127
- feeds_fetched_at = Time.now
128
- Site.all.each do |site|
129
- site.fetched_at = feeds_fetched_at
130
- site.save!
131
- end
132
-
133
- Feed.all.each do |feed_rec|
134
-
135
- feed_key = feed_rec.key
136
- feed_url = feed_rec.feed_url
137
-
138
- feed_xml = fetch_feed( feed_url )
139
-
140
- logger.debug "feed_xml:"
141
- logger.debug feed_xml[ 0..300 ] # get first 300 chars
142
-
143
- # if opts.verbose? # also write a copy to disk
144
- if debug?
145
- logger.debug "saving feed to >./#{feed_key}.xml<..."
146
- File.open( "./#{feed_key}.xml", 'w' ) do |f|
147
- f.write( feed_xml )
148
- end
149
- end
150
-
151
- puts "Before parsing feed >#{feed_key}<..."
152
-
153
- ## fix/todo: check for feed.nil? -> error parsing!!!
154
- # or throw exception
155
- feed = FeedUtils::Parser.parse( feed_xml )
156
-
157
- feed_fetched_at = Time.now
158
-
159
- ## todo/check: move feed_rec update to the end (after item updates??)
160
-
161
- # update feed attribs e.g.
162
- # generator
163
- # published_at,built_at,touched_at,fetched_at
164
- # summary,title2
165
-
166
- ## fix:
167
- ## weird rss exception error on windows w/ dates
168
- # e.g. /lib/ruby/1.9.1/rss/rss.rb:37:in `w3cdtf': wrong number of arguments (1 for 0) (ArgumentError)
169
- #
170
- # move to_datetime to feedutils!! if it works
171
-
172
-
173
- feed_attribs = {
174
- fetched_at: feed_fetched_at,
175
- format: feed.format,
176
- published_at: feed.published? ? feed.published.to_datetime : nil,
177
- touched_at: feed.updated? ? feed.updated.to_datetime : nil,
178
- built_at: feed.built? ? feed.built.to_datetime : nil,
179
- summary: feed.summary? ? feed.summary : nil,
180
- title2: feed.title2? ? feed.title2 : nil,
181
- generator: feed.generator
182
- }
183
-
184
- if debug?
185
- ## puts "*** dump feed_attribs:"
186
- ## pp feed_attribs
187
- puts "*** dump feed_attribs w/ class types:"
188
- feed_attribs.each do |key,value|
189
- puts " #{key}: >#{value}< : #{value.class.name}"
190
- end
191
- end
192
-
193
- feed_rec.update_attributes!( feed_attribs )
194
-
195
-
196
- feed.items.each do |item|
197
-
198
- item_attribs = {
199
- fetched_at: feed_fetched_at,
200
- title: item.title,
201
- url: item.url,
202
- summary: item.summary? ? item.summary : nil,
203
- content: item.content? ? item.content : nil,
204
- published_at: item.published? ? item.published.to_datetime : nil,
205
- touched_at: item.updated? ? item.updated.to_datetime : nil,
206
- feed_id: feed_rec.id # add feed_id fk_ref
207
- }
208
-
209
- if debug?
210
- puts "*** dump item_attribs w/ class types:"
211
- item_attribs.each do |key,value|
212
- next if [:summary,:content].include?( key ) # skip summary n content
213
- puts " #{key}: >#{value}< : #{value.class.name}"
214
- end
215
- end
216
-
217
-
218
- rec = Item.find_by_guid( item.guid )
219
- if rec.nil?
220
- rec = Item.new
221
- item_attribs[ :guid ] = item.guid
222
- puts "** NEW | #{item.title}"
223
- else
224
- ## todo: check if any attribs changed
225
- puts "UPDATE | #{item.title}"
226
- end
12
+ attr_reader :opts, :config
227
13
 
228
- rec.update_attributes!( item_attribs )
229
- end # each item
14
+ def run
15
+ ###################
16
+ # step 1) update subscriptions
17
+ subscriber = Subscriber.new
230
18
 
231
- # update cached value latest published_at for item
232
- item_recs = feed_rec.items.latest.limit(1).all
233
- unless item_recs.empty?
234
- if item_recs[0].published_at?
235
- feed_rec.latest_published_at = item_recs[0].published_at
236
- else # try touched_at
237
- feed_rec.latest_published_at = item_recs[0].touched_at
238
- end
239
- feed_rec.save!
240
- end
19
+ # pass along debug/verbose setting/switch
20
+ subscriber.debug = true if opts.verbose?
21
+ subscriber.update_subscriptions( config )
241
22
 
242
- end # each feed
23
+ ##############################
24
+ # step 2) update feeds
25
+ refresher = Refresher.new
243
26
 
27
+ # pass along debug/verbose setting/switch
28
+ refresher.debug = true if opts.verbose?
29
+ refresher.update_feeds
244
30
  end # method run
245
31
 
246
-
247
- end # class Fetcher
32
+ end # class Updater
248
33
 
249
34
  end # module Pluto
data/lib/pluto/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Pluto
3
- VERSION = '0.8.2'
3
+ VERSION = '0.8.3'
4
4
  end
5
5
 
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ ## $:.unshift(File.dirname(__FILE__))
2
+
3
+
4
+ ## minitest setup
5
+
6
+ # require 'minitest/unit'
7
+ require 'minitest/autorun'
8
+
9
+ # include MiniTest::Unit # lets us use TestCase instead of MiniTest::Unit::TestCase
10
+
11
+
12
+ ## our own code
13
+
14
+ require 'pluto'
15
+
16
+
17
+ LogUtils::Logger.root.level = :debug
18
+
@@ -0,0 +1,75 @@
1
+ # encoding: UTF-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_rss.rb
6
+ # or better
7
+ # rake test
8
+
9
+ require 'helper'
10
+
11
+ class TestHelper < MiniTest::Unit::TestCase
12
+
13
+ include Pluto::TemplateHelper # lets us use textify, etc.
14
+
15
+ def test_textify
16
+ hyin =<<EOS
17
+ <p><img style="float:left; margin-right:4px" src="http://photos1.meetupstatic.com/photos/event/7/c/b/2/event_244651922.jpeg" alt="photo" class="photo" />vienna.rb</p>
18
+ <p>
19
+ <p>The cool guys from <a href="http://platogo.com/">Platogo</a> will sponsor (y)our drinks. Which is awesome.</p>
20
+ <p><strong>Talks</strong>*</p>
21
+ <p>Jakob Sommerhuber - sponsor talk</p>
22
+ <p>Martin Schürrer - Erlang/OTP in production for highly-available, scalable systems</p>
23
+ <p>Markus Prinz - How to improve your code</p>
24
+ <p>Gerald Bauer - working with Sinatra</p>
25
+ <p>Kathrin Folkendt - 'Chapter one' (lightning talk on getting started with Rails, and building her first web app)</p>
26
+ <p><em>*preliminary program</em></p>
27
+ </p>
28
+ <p>Vienna - Austria</p>
29
+ <p>Friday, October 11 at 6:00 PM</p>
30
+ <p>Attending: 21</p>
31
+ <p>Details: http://www.meetup.com/vienna-rb/events/130346182/</p>
32
+ EOS
33
+
34
+ hystep1 = <<EOS
35
+ ‹p›♦vienna.rb‹/p›
36
+ ‹p›
37
+ ‹p›The cool guys from Platogo will sponsor (y)our drinks. Which is awesome.‹/p›
38
+ ‹p›Talks*‹/p›
39
+ ‹p›Jakob Sommerhuber - sponsor talk‹/p›
40
+ ‹p›Martin Schürrer - Erlang/OTP in production for highly-available, scalable systems‹/p›
41
+ ‹p›Markus Prinz - How to improve your code‹/p›
42
+ ‹p›Gerald Bauer - working with Sinatra‹/p›
43
+ ‹p›Kathrin Folkendt - 'Chapter one' (lightning talk on getting started with Rails, and building her first web app)‹/p›
44
+ ‹p›*preliminary program‹/p›
45
+ ‹/p›
46
+ ‹p›Vienna - Austria‹/p›
47
+ ‹p›Friday, October 11 at 6:00 PM‹/p›
48
+ ‹p›Attending: 21‹/p›
49
+ ‹p›Details: www.meetup.com/vienna-rb/events/130346182/‹/p›
50
+ EOS
51
+
52
+ hyout = <<EOS
53
+ <p>♦vienna.rb</p>
54
+ <p>
55
+ <p>The cool guys from Platogo will sponsor (y)our drinks. Which is awesome.</p>
56
+ <p>Talks*</p>
57
+ <p>Jakob Sommerhuber - sponsor talk</p>
58
+ <p>Martin Schürrer - Erlang/OTP in production for highly-available, scalable systems</p>
59
+ <p>Markus Prinz - How to improve your code</p>
60
+ <p>Gerald Bauer - working with Sinatra</p>
61
+ <p>Kathrin Folkendt - 'Chapter one' (lightning talk on getting started with Rails, and building her first web app)</p>
62
+ <p>*preliminary program</p>
63
+ </p>
64
+ <p>Vienna - Austria</p>
65
+ <p>Friday, October 11 at 6:00 PM</p>
66
+ <p>Attending: 21</p>
67
+ <p>Details: www.meetup.com/vienna-rb/events/130346182/</p>
68
+ EOS
69
+
70
+ assert_equal( hyout, textify( hyin ) )
71
+
72
+ assert_equal( hystep1, textify( hyin, skip_restore: true ) )
73
+ end
74
+
75
+ end # class TestHelper
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-24 00:00:00.000000000 Z
12
+ date: 2013-09-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pakman
16
- requirement: &83915310 !ruby/object:Gem::Requirement
16
+ requirement: &75684250 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.5'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *83915310
24
+ version_requirements: *75684250
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fetcher
27
- requirement: &83914830 !ruby/object:Gem::Requirement
27
+ requirement: &75684020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.3'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *83914830
35
+ version_requirements: *75684020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: logutils
38
- requirement: &83914450 !ruby/object:Gem::Requirement
38
+ requirement: &75683730 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,32 +43,32 @@ dependencies:
43
43
  version: '0.6'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *83914450
46
+ version_requirements: *75683730
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: feedutils
49
- requirement: &83914160 !ruby/object:Gem::Requirement
49
+ requirement: &75683490 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: '0.3'
54
+ version: 0.3.2
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *83914160
57
+ version_requirements: *75683490
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: props
60
- requirement: &83913880 !ruby/object:Gem::Requirement
60
+ requirement: &75683190 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
64
64
  - !ruby/object:Gem::Version
65
- version: 1.0.0
65
+ version: 1.0.2
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *83913880
68
+ version_requirements: *75683190
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: textutils
71
- requirement: &83913580 !ruby/object:Gem::Requirement
71
+ requirement: &75682950 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.6.8
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *83913580
79
+ version_requirements: *75682950
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: gli
82
- requirement: &83913340 !ruby/object:Gem::Requirement
82
+ requirement: &75682640 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 2.5.6
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *83913340
90
+ version_requirements: *75682640
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rdoc
93
- requirement: &83913010 !ruby/object:Gem::Requirement
93
+ requirement: &75698770 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '3.10'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *83913010
101
+ version_requirements: *75698770
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: hoe
104
- requirement: &83912770 !ruby/object:Gem::Requirement
104
+ requirement: &75698470 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '3.3'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *83912770
112
+ version_requirements: *75698470
113
113
  description: pluto - Another Planet Generator (Lets You Build Web Pages from Published
114
114
  Web Feeds)
115
- email: webslideshow@googlegroups.com
115
+ email: feedreader@googlegroups.com
116
116
  executables:
117
117
  - pluto
118
118
  extensions: []
@@ -135,10 +135,15 @@ files:
135
135
  - lib/pluto/lister.rb
136
136
  - lib/pluto/manifest_helpers.rb
137
137
  - lib/pluto/models.rb
138
+ - lib/pluto/refresher.rb
138
139
  - lib/pluto/schema.rb
140
+ - lib/pluto/subscriber.rb
139
141
  - lib/pluto/template_helpers.rb
140
142
  - lib/pluto/updater.rb
141
143
  - lib/pluto/version.rb
144
+ - test/helper.rb
145
+ - test/test_helpers.rb
146
+ - .gemtest
142
147
  homepage: https://github.com/feedreader/pluto
143
148
  licenses:
144
149
  - Public Domain
@@ -166,4 +171,5 @@ rubygems_version: 1.8.17
166
171
  signing_key:
167
172
  specification_version: 3
168
173
  summary: pluto - Another Planet Generator
169
- test_files: []
174
+ test_files:
175
+ - test/test_helpers.rb