pluto-news 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -0
- data/Manifest.txt +8 -0
- data/README.md +27 -0
- data/Rakefile +30 -0
- data/lib/pluto/news.rb +159 -0
- data/lib/pluto/news/version.rb +24 -0
- data/test/helper.rb +10 -0
- data/test/test_queries.rb +68 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5df9d5d7f7b8452c64403027473b653119d32419
|
4
|
+
data.tar.gz: d85fe701241dcbfff4592d7d0bb00f67f153a493
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f90a58e50b799f754c541bd29cb3f8bdf6148014d19e1a0b4b17e1e028a83580dae42148d7234f24ba518bc480c0e2f519b7d67f448b3e0b58c8b389bb68b90
|
7
|
+
data.tar.gz: a098aa30542f9ece204ce0c1af07b8ccec9ccb703d66536bdf248921ef0a727689266a2c8de6751f297ee4da3bce3be5fd7cca437ae6eed964fcd1d1b0372877
|
data/CHANGELOG.md
ADDED
data/Manifest.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# pluto-news gem - newsreader for easy (re)use - build your own facebook newsfeed in 5 minutes
|
2
|
+
|
3
|
+
|
4
|
+
* home :: [github.com/feedreader/pluto](https://github.com/feedreader/pluto)
|
5
|
+
* bugs :: [github.com/feedreader/pluto/issues](https://github.com/feedreader/pluto/issues)
|
6
|
+
* gem :: [rubygems.org/gems/pluto-news](https://rubygems.org/gems/pluto-news)
|
7
|
+
* rdoc :: [rubydoc.info/gems/pluto-news](http://rubydoc.info/gems/pluto-news)
|
8
|
+
* forum :: [groups.google.com/group/wwwmake](http://groups.google.com/group/wwwmake)
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
To be done
|
15
|
+
|
16
|
+
|
17
|
+
## License
|
18
|
+
|
19
|
+
![](https://publicdomainworks.github.io/buttons/zero88x31.png)
|
20
|
+
|
21
|
+
The `pluto-news` scripts are dedicated to the public domain.
|
22
|
+
Use it as you please with no restrictions whatsoever.
|
23
|
+
|
24
|
+
## Questions? Comments?
|
25
|
+
|
26
|
+
Send them along to the [wwwmake Forum/Mailing List](http://groups.google.com/group/wwwmake).
|
27
|
+
Thanks!
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
require './lib/pluto/news/version.rb'
|
3
|
+
|
4
|
+
Hoe.spec 'pluto-news' do
|
5
|
+
|
6
|
+
self.version = PlutoNews::VERSION
|
7
|
+
|
8
|
+
self.summary = "pluto-news - newsreader for easy (re)use - build your own facebook newsfeed in 5 minutes"
|
9
|
+
self.description = summary
|
10
|
+
|
11
|
+
self.urls = ['https://github.com/feedreader/pluto']
|
12
|
+
|
13
|
+
self.author = 'Gerald Bauer'
|
14
|
+
self.email = 'wwwmake@googlegroups.com'
|
15
|
+
|
16
|
+
# switch extension to .markdown for gihub formatting
|
17
|
+
self.readme_file = 'README.md'
|
18
|
+
self.history_file = 'CHANGELOG.md'
|
19
|
+
|
20
|
+
self.extra_deps = [
|
21
|
+
['pluto-models', '>= 1.5.4'],
|
22
|
+
]
|
23
|
+
|
24
|
+
self.licenses = ['Public Domain']
|
25
|
+
|
26
|
+
self.spec_extras = {
|
27
|
+
required_ruby_version: '>= 2.2.2'
|
28
|
+
}
|
29
|
+
|
30
|
+
end
|
data/lib/pluto/news.rb
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'pluto/update'
|
2
|
+
|
3
|
+
|
4
|
+
## our own code
|
5
|
+
require 'pluto/news/version'
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
module News
|
10
|
+
|
11
|
+
def self.subscribe( *feeds )
|
12
|
+
site_hash = { ## note: keys are strings (NOT symbols) for now
|
13
|
+
'title' => 'News, News, News'
|
14
|
+
}
|
15
|
+
|
16
|
+
feeds.each_with_index do |feed,i|
|
17
|
+
key = "feed%03d" % (i+1)
|
18
|
+
## todo/fix:
|
19
|
+
## use auto_title and auto_link
|
20
|
+
## do NOT add title and link (will overwrite/rule auto_title and auto_link updates)
|
21
|
+
site_hash[ key ] = { 'title' => "Untitled %03d" % (i+1),
|
22
|
+
'link' => 'http://example.com', ## todo/fix - make optional?
|
23
|
+
'feed' => feed
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
connection ## make sure we have a database connection (and setup) up-and-running
|
28
|
+
site_key = 'news' ## note: use always news (and single-site setup) for now
|
29
|
+
Pluto::Model::Site.deep_create_or_update_from_hash!( site_key, site_hash )
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.update
|
33
|
+
connection ## make sure we have a database connection (and setup) up-and-running
|
34
|
+
Pluto.update_feeds
|
35
|
+
end
|
36
|
+
def self.refresh() update; end ## convenience alias for update
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
def self.feeds
|
41
|
+
connection
|
42
|
+
## note: add "default" scope - orders (sorts) by latest / time
|
43
|
+
Pluto::Model::Feed.order(
|
44
|
+
Arel.sql( "coalesce(feeds.updated,feeds.published,'1970-01-01') desc" )
|
45
|
+
)
|
46
|
+
end
|
47
|
+
def self.channels() feeds; end ## convenience alias for feeds
|
48
|
+
|
49
|
+
|
50
|
+
def self.items
|
51
|
+
connection ## make sure we have a database connection (and setup) up-and-running
|
52
|
+
## note: add "default" scope - orders (sorts) by latest / time
|
53
|
+
Pluto::Model::Item.order(
|
54
|
+
Arel.sql( "coalesce(items.updated,items.published,'1970-01-01') desc" )
|
55
|
+
)
|
56
|
+
end
|
57
|
+
def self.latest() items; end ## note: "default" scope orders (sorts) by latest / time
|
58
|
+
|
59
|
+
|
60
|
+
def self.today
|
61
|
+
## todo: order by time!! - possible - why? why not?
|
62
|
+
## note: use date() to cut-off hours etc. if present?
|
63
|
+
|
64
|
+
q = Date.today.strftime('%Y-%m-%d') # e.g. 2020-02-20
|
65
|
+
items.
|
66
|
+
where(
|
67
|
+
Arel.sql( "date(coalesce(items.updated,items.published)) = '#{q}'" )
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def self.between( start_date, end_date ) ## helper for week, q1, q2, etc.
|
73
|
+
q_start = start_date.strftime('%Y-%m-%d')
|
74
|
+
q_end = end_date.strftime('%Y-%m-%d')
|
75
|
+
|
76
|
+
items.
|
77
|
+
where(
|
78
|
+
Arel.sql( "date(coalesce(items.updated,items.published,'1970-01-01')) BETWEEN '#{q_start}' AND '#{q_end}'" )
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.week( week=Date.today.cweek, year=Date.today.year )
|
83
|
+
## note: SQLite only supports "classic" week of year (not ISO "commercial week" starting on monday - and not on sunday)
|
84
|
+
## %W - week of year: 00-53
|
85
|
+
## thus, needs to calculate start and end date!!!
|
86
|
+
|
87
|
+
start_date = Date.commercial(year, week, 1)
|
88
|
+
end_date = Date.commercial(year, week, 7)
|
89
|
+
|
90
|
+
between( start_date, end_date )
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.month( month=Date.today.month, year=Date.today.year )
|
94
|
+
q = "%4d-%02d" % [year,month] # e.g. 2020-01 etc.
|
95
|
+
items.
|
96
|
+
where(
|
97
|
+
Arel.sql( "strftime('%Y-%m', coalesce(items.updated,items.published,'1970-01-01')) = '#{q}'" )
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.year( year=Date.today.year )
|
102
|
+
q = year
|
103
|
+
items.
|
104
|
+
where(
|
105
|
+
Arel.sql( "strftime('%Y', coalesce(items.updated,items.published,'1970-01-01')) = '#{q}'" )
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.this_week() week; end ## convenience alias - keep - why? why not?
|
110
|
+
def self.this_month() month; end
|
111
|
+
def self.this_year() year; end
|
112
|
+
|
113
|
+
|
114
|
+
def self.q1( year=Date.today.year ) between( Date.new( year, 1, 1), Date.new( year, 3, 31) ); end
|
115
|
+
def self.q2( year=Date.today.year ) between( Date.new( year, 4, 1), Date.new( year, 6, 30) ); end
|
116
|
+
def self.q3( year=Date.today.year ) between( Date.new( year, 7, 1), Date.new( year, 9, 30) ); end
|
117
|
+
def self.q4( year=Date.today.year ) between( Date.new( year, 10, 1), Date.new( year,12, 31) ); end
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
class Configuration
|
122
|
+
def database=(value) @database = value; end
|
123
|
+
def database() @database || { adapter: 'sqlite3', database: './news.db' }; end
|
124
|
+
end # class Configuration
|
125
|
+
|
126
|
+
def self.configure
|
127
|
+
yield( config )
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.config
|
131
|
+
@config ||= Configuration.new
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
class Connection
|
136
|
+
def initialize # convenience shortcut w/ automigrate
|
137
|
+
config = if News.config.database.is_a?(Hash)
|
138
|
+
News.config.database
|
139
|
+
else ## assume a string (e.g. :memory:, or <path> AND sqlite3 adapter)
|
140
|
+
{ adapter: 'sqlite3', database: News.config.database }
|
141
|
+
end
|
142
|
+
|
143
|
+
Pluto.connect( config )
|
144
|
+
Pluto.auto_migrate!
|
145
|
+
end
|
146
|
+
end # class Connection
|
147
|
+
|
148
|
+
def self.connection ## use for "auto-magic" connection w/ automigrate
|
149
|
+
## todo/fix: check - "just simply" return ActiveRecord connection - possible - why? why not?
|
150
|
+
## do NOT use our own Connection class
|
151
|
+
@connection ||= Connection.new
|
152
|
+
end
|
153
|
+
end # module News
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
# say hello
|
159
|
+
puts PlutoNews.banner if $DEBUG || (defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PlutoNews
|
4
|
+
|
5
|
+
MAJOR = 0
|
6
|
+
MINOR = 1
|
7
|
+
PATCH = 0
|
8
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
9
|
+
|
10
|
+
def self.version
|
11
|
+
VERSION
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.banner
|
15
|
+
### todo: add RUBY_PATCHLEVEL or RUBY_PATCH_LEVEL e.g. -p124
|
16
|
+
"pluto-news/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.root
|
20
|
+
"#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
|
21
|
+
end
|
22
|
+
|
23
|
+
end # module PlutoNews
|
24
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
###
|
2
|
+
# to run use
|
3
|
+
# ruby -I ./lib -I ./test test/test_queries.rb
|
4
|
+
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
class TestQueries < MiniTest::Test
|
9
|
+
|
10
|
+
def test_queries
|
11
|
+
puts News.channels.to_sql
|
12
|
+
puts News.feeds.to_sql
|
13
|
+
|
14
|
+
puts News.items.to_sql
|
15
|
+
|
16
|
+
|
17
|
+
puts News.latest.limit(2).to_sql
|
18
|
+
puts News.today.to_sql
|
19
|
+
|
20
|
+
puts News.week.to_sql
|
21
|
+
puts News.week( 1 ).to_sql
|
22
|
+
puts News.week( 1, 2019 ).to_sql
|
23
|
+
|
24
|
+
puts News.month.to_sql
|
25
|
+
puts News.month( 1 ).to_sql
|
26
|
+
puts News.month( 1, 2019 ).to_sql
|
27
|
+
|
28
|
+
puts News.year.to_sql
|
29
|
+
puts News.year( 2019 ).to_sql
|
30
|
+
|
31
|
+
puts News.this_week.to_sql
|
32
|
+
puts News.this_month.to_sql
|
33
|
+
puts News.this_year.to_sql
|
34
|
+
|
35
|
+
puts News.q1.to_sql
|
36
|
+
puts News.q2.to_sql
|
37
|
+
puts News.q3.to_sql
|
38
|
+
puts News.q4.to_sql
|
39
|
+
|
40
|
+
|
41
|
+
###### run queries
|
42
|
+
pp News.latest.limit(2).to_a
|
43
|
+
pp News.today.to_a
|
44
|
+
|
45
|
+
pp News.week.to_a
|
46
|
+
pp News.week( 1 ).to_a
|
47
|
+
pp News.week( 1, 2019 ).to_a
|
48
|
+
|
49
|
+
pp News.month.to_a
|
50
|
+
pp News.month( 1 ).to_a
|
51
|
+
pp News.month( 1, 2019 ).to_a
|
52
|
+
|
53
|
+
pp News.year.to_a
|
54
|
+
pp News.year( 2019 ).to_a
|
55
|
+
|
56
|
+
pp News.this_week.to_a
|
57
|
+
pp News.this_month.to_a
|
58
|
+
pp News.this_year.to_a
|
59
|
+
|
60
|
+
pp News.q1.to_a
|
61
|
+
pp News.q2.to_a
|
62
|
+
pp News.q3.to_a
|
63
|
+
pp News.q4.to_a
|
64
|
+
|
65
|
+
assert true
|
66
|
+
end
|
67
|
+
|
68
|
+
end # class TestQueries
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pluto-news
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gerald Bauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pluto-models
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.5.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.5.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: hoe
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.16'
|
55
|
+
description: pluto-news - newsreader for easy (re)use - build your own facebook newsfeed
|
56
|
+
in 5 minutes
|
57
|
+
email: wwwmake@googlegroups.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files:
|
61
|
+
- CHANGELOG.md
|
62
|
+
- Manifest.txt
|
63
|
+
- README.md
|
64
|
+
files:
|
65
|
+
- CHANGELOG.md
|
66
|
+
- Manifest.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/pluto/news.rb
|
70
|
+
- lib/pluto/news/version.rb
|
71
|
+
- test/helper.rb
|
72
|
+
- test/test_queries.rb
|
73
|
+
homepage: https://github.com/feedreader/pluto
|
74
|
+
licenses:
|
75
|
+
- Public Domain
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options:
|
79
|
+
- "--main"
|
80
|
+
- README.md
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 2.2.2
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.5.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: pluto-news - newsreader for easy (re)use - build your own facebook newsfeed
|
99
|
+
in 5 minutes
|
100
|
+
test_files: []
|