pluto 0.8.6 → 0.8.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pluto/cli/main.rb +3 -3
- data/lib/pluto/fetcher.rb +4 -4
- data/lib/pluto/formatter.rb +19 -9
- data/lib/pluto/models/feed.rb +1 -1
- data/lib/pluto/models/item.rb +1 -1
- data/lib/pluto/models/utils.rb +8 -4
- data/lib/pluto/refresher.rb +63 -41
- data/lib/pluto/schema.rb +6 -0
- data/lib/pluto/subscriber.rb +16 -11
- data/lib/pluto/updater.rb +9 -3
- data/lib/pluto/version.rb +1 -1
- metadata +19 -19
data/lib/pluto/cli/main.rb
CHANGED
@@ -285,9 +285,9 @@ command [:update, :up, :u] do |c|
|
|
285
285
|
|
286
286
|
config = load_config( arg )
|
287
287
|
|
288
|
-
Pluto::Updater.new( opts, config ).run
|
288
|
+
Pluto::Updater.new( opts, config ).run( name )
|
289
289
|
end
|
290
|
-
|
290
|
+
|
291
291
|
puts 'Done.'
|
292
292
|
end
|
293
293
|
end # command fetch
|
@@ -326,7 +326,7 @@ command [:build, :b] do |c|
|
|
326
326
|
|
327
327
|
config = load_config( arg )
|
328
328
|
|
329
|
-
Pluto::Updater.new( opts, config ).run
|
329
|
+
Pluto::Updater.new( opts, config ).run( name )
|
330
330
|
Pluto::Formatter.new( opts, config ).run( name )
|
331
331
|
end
|
332
332
|
|
data/lib/pluto/fetcher.rb
CHANGED
@@ -16,12 +16,12 @@ class Fetcher
|
|
16
16
|
def fetch_feed( url )
|
17
17
|
response = @worker.get( url )
|
18
18
|
|
19
|
-
if debug?
|
19
|
+
## if debug?
|
20
20
|
puts "http status #{response.code} #{response.message}"
|
21
21
|
|
22
22
|
puts "http header - etag: #{response.header['etag']} - #{response.header['etag'].class.name}"
|
23
23
|
puts "http header - last-modified: #{response.header['last-modified']} - #{response.header['last-modified'].class.name}"
|
24
|
-
end
|
24
|
+
## end
|
25
25
|
|
26
26
|
xml = response.body
|
27
27
|
|
@@ -130,10 +130,10 @@ class Fetcher
|
|
130
130
|
fetched: feed_fetched
|
131
131
|
}
|
132
132
|
|
133
|
-
if debug?
|
133
|
+
## if debug?
|
134
134
|
puts "http header - etag: #{response.header['etag']} - #{response.header['etag'].class.name}"
|
135
135
|
puts "http header - last-modified: #{response.header['last-modified']} - #{response.header['last-modified'].class.name}"
|
136
|
-
end
|
136
|
+
## end
|
137
137
|
|
138
138
|
feed_rec.update_attributes!( feed_attribs )
|
139
139
|
|
data/lib/pluto/formatter.rb
CHANGED
@@ -16,13 +16,29 @@ class Formatter
|
|
16
16
|
|
17
17
|
attr_reader :opts, :config, :site
|
18
18
|
|
19
|
+
|
19
20
|
def run( arg )
|
21
|
+
### remove - always use make( site_key )
|
20
22
|
## fix: change arg to planet_key or just key or similar
|
21
23
|
# todo: rename run to some less generic - merge/build/etc. ??
|
22
24
|
|
25
|
+
site_key = arg
|
26
|
+
site_key = site_key.downcase.gsub('.ini','').gsub('.yml','') # remove .ini|.yml extension if present
|
27
|
+
|
23
28
|
manifest_name = opts.manifest
|
29
|
+
output_path = opts.output_path
|
30
|
+
|
31
|
+
make_for(site_key, manifest_name, output_path )
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def make_for( site_key, manifest_name, output_path )
|
36
|
+
|
37
|
+
## fix: remove reference to opts
|
38
|
+
## - e.g. now still used for auto-installer
|
39
|
+
|
24
40
|
manifest_name = manifest_name.downcase.gsub('.txt', '' ) # remove .txt if present
|
25
|
-
|
41
|
+
|
26
42
|
logger.debug "manifest=#{manifest_name}"
|
27
43
|
|
28
44
|
# check for matching manifests
|
@@ -47,14 +63,8 @@ class Formatter
|
|
47
63
|
end
|
48
64
|
|
49
65
|
manifestsrc = manifests[0][1]
|
50
|
-
pakpath =
|
51
|
-
|
52
|
-
name = arg
|
53
|
-
|
54
|
-
## for now - use single site w/ key planet
|
55
|
-
##-- fix!! allow multiple sites (planets)
|
66
|
+
pakpath = output_path
|
56
67
|
|
57
|
-
site_key = 'planet'
|
58
68
|
@site = Site.find_by_key( site_key )
|
59
69
|
if @site.nil?
|
60
70
|
puts "*** warn: no site with key '#{site_key}' found; using untitled site record"
|
@@ -62,7 +72,7 @@ class Formatter
|
|
62
72
|
@site.title = 'Planet Untitled'
|
63
73
|
end
|
64
74
|
|
65
|
-
Pakman::Templater.new.merge_pak( manifestsrc, pakpath, binding,
|
75
|
+
Pakman::Templater.new.merge_pak( manifestsrc, pakpath, binding, site_key )
|
66
76
|
end
|
67
77
|
|
68
78
|
end # class Formatter
|
data/lib/pluto/models/feed.rb
CHANGED
@@ -17,7 +17,7 @@ class Feed < ActiveRecord::Base
|
|
17
17
|
|
18
18
|
# note: if not published, touched or built use hardcoded 1971-01-01 for now
|
19
19
|
## order( "coalesce(published,touched,built,'1971-01-01') desc" )
|
20
|
-
order( "coalesce(last_published,'1971-01-01') desc" )
|
20
|
+
order( "coalesce(feeds.last_published,'1971-01-01') desc" )
|
21
21
|
end
|
22
22
|
|
23
23
|
##################################
|
data/lib/pluto/models/item.rb
CHANGED
@@ -24,7 +24,7 @@ class Item < ActiveRecord::Base
|
|
24
24
|
# coalesce - supported by sqlite (yes), postgres (yes)
|
25
25
|
|
26
26
|
# note: if not published,touched or built_at use hardcoded 1971-01-01 for now
|
27
|
-
order( "coalesce(published,touched,'1971-01-01') desc" )
|
27
|
+
order( "coalesce(items.published,items.touched,'1971-01-01') desc" )
|
28
28
|
end
|
29
29
|
|
30
30
|
def published?() read_attribute(:published).present?; end
|
data/lib/pluto/models/utils.rb
CHANGED
@@ -23,14 +23,18 @@ class ItemCursor
|
|
23
23
|
new_date = true
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
## note:
|
27
|
+
# new date also **always** starts new feed
|
28
|
+
# - e.g. used for grouping within day (follows planet planet convention)
|
29
|
+
|
30
|
+
if new_date || last_feed_id != item.feed.id
|
29
31
|
new_feed = true
|
32
|
+
else
|
33
|
+
new_feed = false
|
30
34
|
end
|
31
35
|
|
32
36
|
yield( item, new_date, new_feed )
|
33
|
-
|
37
|
+
|
34
38
|
last_published = item.published
|
35
39
|
last_feed_id = item.feed.id
|
36
40
|
end
|
data/lib/pluto/refresher.rb
CHANGED
@@ -13,8 +13,8 @@ class Refresher
|
|
13
13
|
def debug=(value) @debug = value; end
|
14
14
|
def debug?() @debug || false; end
|
15
15
|
|
16
|
-
def update_feeds( opts={} )
|
17
16
|
|
17
|
+
def update_feeds( opts={} ) # update all feeds
|
18
18
|
if debug?
|
19
19
|
## turn on logging for sql too
|
20
20
|
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
@@ -23,61 +23,83 @@ class Refresher
|
|
23
23
|
|
24
24
|
# -- log update action
|
25
25
|
Action.create!( title: 'update feeds' )
|
26
|
+
|
27
|
+
feeds_fetched = Time.now
|
28
|
+
Site.all.each do |site|
|
29
|
+
site.update_attributes!( fetched: feeds_fetched )
|
30
|
+
end
|
31
|
+
|
32
|
+
Feed.all.each do |feed|
|
33
|
+
update_feed_worker( feed )
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def update_feeds_for( site_key, opts={} )
|
39
|
+
if debug?
|
40
|
+
## turn on logging for sql too
|
41
|
+
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
42
|
+
@worker.debug = true # also pass along worker debug flag if set
|
43
|
+
end
|
44
|
+
|
45
|
+
# -- log update action
|
46
|
+
Action.create!( title: "update feeds >#{site_key}<" )
|
26
47
|
|
27
48
|
#####
|
28
49
|
# -- update fetched timestamps for all sites
|
29
50
|
feeds_fetched = Time.now
|
30
|
-
|
31
|
-
|
32
|
-
|
51
|
+
|
52
|
+
site = Site.find_by_key!( site_key )
|
53
|
+
site.update_attributes!( fetched: feeds_fetched )
|
54
|
+
|
55
|
+
site.feeds.each do |feed|
|
56
|
+
update_feed_worker( feed )
|
33
57
|
end
|
34
58
|
|
35
|
-
|
59
|
+
end # method update_feeds
|
36
60
|
|
37
|
-
|
61
|
+
private
|
62
|
+
def update_feed_worker( feed_rec )
|
63
|
+
feed = @worker.feed_by_rec_if_modified( feed_rec )
|
38
64
|
|
39
|
-
|
40
|
-
|
65
|
+
# on error or if http-not modified etc. skip update/processing
|
66
|
+
return if feed.nil?
|
41
67
|
|
42
|
-
|
43
|
-
|
68
|
+
## fix/todo: reload feed_red - fetched date updated etc.
|
69
|
+
## check if needed for access to fetched date
|
44
70
|
|
45
71
|
|
46
|
-
|
72
|
+
## todo/check: move feed_rec update to the end (after item updates??)
|
47
73
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
74
|
+
# update feed attribs e.g.
|
75
|
+
# generator
|
76
|
+
# published_at,built_at,touched_at,fetched_at
|
77
|
+
# summary,title2
|
52
78
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
79
|
+
## fix:
|
80
|
+
## weird rss exception error on windows w/ dates
|
81
|
+
# e.g. /lib/ruby/1.9.1/rss/rss.rb:37:in `w3cdtf': wrong number of arguments (1 for 0) (ArgumentError)
|
82
|
+
#
|
83
|
+
# move to_datetime to feedutils!! if it works
|
84
|
+
## todo: move this comments to feedutils??
|
85
|
+
|
86
|
+
|
87
|
+
feed_rec.debug = debug? ? true : false # pass along debug flag
|
88
|
+
## fix/todo: pass debug flag as opts - debug: true|false !!!!!!
|
89
|
+
feed_rec.save_from_struct!( feed ) # todo: find a better name - why? why not??
|
90
|
+
|
91
|
+
|
92
|
+
# update cached value last published for item
|
93
|
+
last_item_rec = feed_rec.items.latest.limit(1).first # note limit(1) will return relation/arrar - use first to get first element or nil from ary
|
94
|
+
if last_item_rec.present?
|
95
|
+
if last_item_rec.published?
|
96
|
+
feed_rec.update_attributes!( last_published: last_item_rec.published )
|
97
|
+
else # try touched
|
98
|
+
feed_rec.update_attributes!( last_published: last_item_rec.touched )
|
74
99
|
end
|
100
|
+
end
|
101
|
+
end # method update_feed_worker
|
75
102
|
|
76
|
-
end # each feed
|
77
|
-
|
78
|
-
end # method update_feeds
|
79
|
-
|
80
|
-
|
81
103
|
end # class Refresher
|
82
104
|
|
83
105
|
end # module Pluto
|
data/lib/pluto/schema.rb
CHANGED
@@ -9,6 +9,12 @@ class CreateDb < ActiveRecord::Migration
|
|
9
9
|
t.string :key, :null => false # e.g. ruby, js, etc.
|
10
10
|
t.datetime :fetched # last fetched/checked date -- make not null ??
|
11
11
|
|
12
|
+
############
|
13
|
+
# filters (site-wide)
|
14
|
+
t.string :includes # regex
|
15
|
+
t.string :excludes # regex
|
16
|
+
|
17
|
+
|
12
18
|
t.timestamps # created_at, updated_at
|
13
19
|
end
|
14
20
|
|
data/lib/pluto/subscriber.rb
CHANGED
@@ -11,15 +11,17 @@ class Subscriber
|
|
11
11
|
|
12
12
|
|
13
13
|
def update_subscriptions( config, opts={} )
|
14
|
+
# !!!! -- depreciated API - remove - do NOT use anymore
|
15
|
+
puts "warn - [Pluto::Subscriber] depreciated API -- use update_subscriptions_for( site_key)"
|
16
|
+
update_subscriptions_for( 'planet', config, opts ) # default to planet site_key
|
17
|
+
end
|
14
18
|
|
19
|
+
|
20
|
+
def update_subscriptions_for( site_key, config, opts={} )
|
15
21
|
site_attribs = {
|
16
|
-
title: config[
|
22
|
+
title: config['title'] || config['name'] # support either title or name
|
17
23
|
}
|
18
|
-
|
19
|
-
## for now - use single site w/ key planet
|
20
|
-
## -- fix!! allow multiple sites (planets)
|
21
|
-
|
22
|
-
site_key = 'planet'
|
24
|
+
|
23
25
|
site_rec = Site.find_by_key( site_key )
|
24
26
|
if site_rec.nil?
|
25
27
|
site_rec = Site.new
|
@@ -27,12 +29,12 @@ class Subscriber
|
|
27
29
|
|
28
30
|
## use object_id: site.id and object_type: Site
|
29
31
|
## change - model/table/schema!!!
|
30
|
-
Action.create!( title:
|
32
|
+
Action.create!( title: "new site >#{site_key}<", object: site_attribs[ :title ] )
|
31
33
|
end
|
32
34
|
site_rec.update_attributes!( site_attribs )
|
33
35
|
|
34
36
|
# -- log update action
|
35
|
-
Action.create!( title:
|
37
|
+
Action.create!( title: "update subscriptions >#{site_key}<" )
|
36
38
|
|
37
39
|
# clean out subscriptions and add again
|
38
40
|
logger.debug "before site.subscriptions.delete_all - count: #{site_rec.subscriptions.count}"
|
@@ -44,7 +46,10 @@ class Subscriber
|
|
44
46
|
## todo: downcase key - why ??? why not???
|
45
47
|
|
46
48
|
# skip "top-level" feed keys e.g. title, etc. or planet planet sections (e.g. planet,defaults)
|
47
|
-
next if ['title','title2','name',
|
49
|
+
next if ['title','title2','name',
|
50
|
+
'include','includes','exclude','excludes',
|
51
|
+
'feeds',
|
52
|
+
'planet','defaults'].include?( key )
|
48
53
|
|
49
54
|
### todo/check:
|
50
55
|
## check value - must be hash
|
@@ -76,9 +81,9 @@ class Subscriber
|
|
76
81
|
## use object_id: feed.id and object_type: Feed
|
77
82
|
## change - model/table/schema!!!
|
78
83
|
## todo: add parent_action_id - why? why not?
|
79
|
-
Action.create!( title:
|
84
|
+
Action.create!( title: "new feed >#{feed_key}<", object: feed_attribs[ :title ] )
|
80
85
|
end
|
81
|
-
|
86
|
+
|
82
87
|
feed_rec.update_attributes!( feed_attribs )
|
83
88
|
|
84
89
|
# add subscription record
|
data/lib/pluto/updater.rb
CHANGED
@@ -11,14 +11,20 @@ class Updater
|
|
11
11
|
|
12
12
|
attr_reader :opts, :config
|
13
13
|
|
14
|
-
def run
|
14
|
+
def run( arg )
|
15
|
+
arg = arg.downcase.gsub('.ini','').gsub('.yml','') # remove file extension if present
|
16
|
+
|
17
|
+
update_for( arg )
|
18
|
+
end
|
19
|
+
|
20
|
+
def update_for( site_key )
|
15
21
|
###################
|
16
22
|
# step 1) update subscriptions
|
17
23
|
subscriber = Subscriber.new
|
18
24
|
|
19
25
|
# pass along debug/verbose setting/switch
|
20
26
|
subscriber.debug = true if opts.verbose?
|
21
|
-
subscriber.
|
27
|
+
subscriber.update_subscriptions_for( site_key, config )
|
22
28
|
|
23
29
|
##############################
|
24
30
|
# step 2) update feeds
|
@@ -26,7 +32,7 @@ class Updater
|
|
26
32
|
|
27
33
|
# pass along debug/verbose setting/switch
|
28
34
|
refresher.debug = true if opts.verbose?
|
29
|
-
refresher.
|
35
|
+
refresher.update_feeds_for( site_key )
|
30
36
|
end # method run
|
31
37
|
|
32
38
|
end # class Updater
|
data/lib/pluto/version.rb
CHANGED
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.
|
4
|
+
version: 0.8.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2013-10-04 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pakman
|
16
|
-
requirement: &
|
16
|
+
requirement: &79324440 !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: *
|
24
|
+
version_requirements: *79324440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: fetcher
|
27
|
-
requirement: &
|
27
|
+
requirement: &79324160 !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: *
|
35
|
+
version_requirements: *79324160
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: logutils
|
38
|
-
requirement: &
|
38
|
+
requirement: &79323870 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0.6'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *79323870
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: feedutils
|
49
|
-
requirement: &
|
49
|
+
requirement: &79323600 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.3.2
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *79323600
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: props
|
60
|
-
requirement: &
|
60
|
+
requirement: &79323280 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.0.2
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *79323280
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: textutils
|
71
|
-
requirement: &
|
71
|
+
requirement: &79323050 !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: *
|
79
|
+
version_requirements: *79323050
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: gli
|
82
|
-
requirement: &
|
82
|
+
requirement: &79322720 !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: *
|
90
|
+
version_requirements: *79322720
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rdoc
|
93
|
-
requirement: &
|
93
|
+
requirement: &79322460 !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: *
|
101
|
+
version_requirements: *79322460
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: hoe
|
104
|
-
requirement: &
|
104
|
+
requirement: &79322170 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '3.3'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *79322170
|
113
113
|
description: pluto - Another Planet Generator (Lets You Build Web Pages from Published
|
114
114
|
Web Feeds)
|
115
115
|
email: feedreader@googlegroups.com
|