rss_notifier 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/.gitignore +13 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +10 -0
- data/bin/rss_notifier +6 -0
- data/lib/rss_notifier.rb +14 -0
- data/lib/rss_notifier/adapter.rb +7 -0
- data/lib/rss_notifier/adapter/email.html.erb +63 -0
- data/lib/rss_notifier/adapter/email.rb +38 -0
- data/lib/rss_notifier/adapter/pushbullet.rb +48 -0
- data/lib/rss_notifier/app.rb +121 -0
- data/lib/rss_notifier/cli.rb +25 -0
- data/lib/rss_notifier/config.rb +40 -0
- data/lib/rss_notifier/db.rb +71 -0
- data/lib/rss_notifier/item.rb +60 -0
- data/lib/rss_notifier/version.rb +3 -0
- data/rss_notifier.gemspec +31 -0
- metadata +178 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 89d2b6a547b17c4f73370e8160a5b67995efc53d
|
4
|
+
data.tar.gz: 02504ee21a129b9aaa58fa40fef7c4615b484e75
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 919f4d56a33dab22e070bff1ef141a8e448afb4dbd96943b86c5c977683f275189a3f98708fe456b469e9cbb7f3505abffe03492326763ca3b73d0a16dd07c73
|
7
|
+
data.tar.gz: faee913387a91de0fdf652932ea328c1e2bf4a3553ac09ae46b84710f4e9b2bc710ec884368b29584700b1854e6953f14d4da009205fb86fa180a245a86bae98
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at mzhomart@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Zhomart Mukhamejanov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# RssNotifier
|
2
|
+
|
3
|
+
It checks given rss urls every given period and notifies you using [Pushbullet](https://www.pushbullet.com).
|
4
|
+
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
Install the gem
|
9
|
+
|
10
|
+
```
|
11
|
+
$ gem install rss_notifier
|
12
|
+
```
|
13
|
+
|
14
|
+
Then initialize it somewhere
|
15
|
+
|
16
|
+
```
|
17
|
+
$ mkdir ~/craigslist
|
18
|
+
$ cd ~/craigslist
|
19
|
+
$ rss_notifier init --force
|
20
|
+
$ vim config.yml
|
21
|
+
$ rss_notifier start
|
22
|
+
<CTRL-C> load initial rss content without notification.
|
23
|
+
$ rss_notifier start --notify
|
24
|
+
```
|
25
|
+
|
26
|
+
If you want it to run in the background, use `tmux`.
|
27
|
+
|
28
|
+
|
29
|
+
## Craigslist
|
30
|
+
|
31
|
+
1. Create a search url on craigslist, e.g. http://sfbay.craigslist.org/search/bik?query=trek+520
|
32
|
+
2. Make it RSS by clicking `RSS` on the bottom-right of the page, e.g. https://sfbay.craigslist.org/search/bik?format=rss&query=trek%20520
|
33
|
+
3. Install gem and initialize it.
|
34
|
+
4. Add RSS link to the `config.yml`.
|
35
|
+
5. Start `rss_notifier`.
|
36
|
+
|
37
|
+
|
38
|
+
## Development
|
39
|
+
|
40
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
41
|
+
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rss_notifier. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
46
|
+
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/rss_notifier
ADDED
data/lib/rss_notifier.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
|
5
|
+
<style>
|
6
|
+
.row {
|
7
|
+
width: 100%;
|
8
|
+
}
|
9
|
+
.mini-info {
|
10
|
+
float:left;
|
11
|
+
width: 40%;
|
12
|
+
border-right: 1px solid #777;
|
13
|
+
padding-left: 10px;
|
14
|
+
}
|
15
|
+
.attrs {
|
16
|
+
float: left;
|
17
|
+
width: 50%;
|
18
|
+
padding-left: 20px;
|
19
|
+
}
|
20
|
+
|
21
|
+
.clearfix { clear: both; }
|
22
|
+
|
23
|
+
p.attrgroup span {
|
24
|
+
display: inline-block;
|
25
|
+
margin: 3px 10px;
|
26
|
+
border: 1px solid #888;
|
27
|
+
padding: 2px 5px;
|
28
|
+
}
|
29
|
+
|
30
|
+
.postinginfos > p {
|
31
|
+
display: inline;
|
32
|
+
margin-left: 20px;
|
33
|
+
}
|
34
|
+
|
35
|
+
.postinginfos time {
|
36
|
+
border-bottom: 1px dotted #999;
|
37
|
+
}
|
38
|
+
|
39
|
+
.postinginfos time:hover {
|
40
|
+
cursor: pointer;
|
41
|
+
}
|
42
|
+
</style>
|
43
|
+
</head>
|
44
|
+
<body>
|
45
|
+
<h1><a href="<%= item.link %>"><%= item.title %></a></h1>
|
46
|
+
<hr>
|
47
|
+
<div class="row">
|
48
|
+
<div class="mini-info">
|
49
|
+
<b>RSS URL:</b> <span style="word-wrap: break-word;"><%= item.rss_url %></span> <br><br>
|
50
|
+
<b>Date:</b> <%= item.date.strftime('%Y-%m-%d %H:%M:%S') %> <br>
|
51
|
+
</div>
|
52
|
+
<div class="clearfix"></div>
|
53
|
+
</div>
|
54
|
+
<hr>
|
55
|
+
|
56
|
+
<hr>
|
57
|
+
|
58
|
+
<section id="postingbody">
|
59
|
+
<%= item.description %>
|
60
|
+
</section>
|
61
|
+
|
62
|
+
</body>
|
63
|
+
</html>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'http'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module RssNotifier
|
5
|
+
module Adapter
|
6
|
+
class Email
|
7
|
+
|
8
|
+
attr_reader :email
|
9
|
+
|
10
|
+
HTML_TEMPLATE = File.expand_path('../email.html.erb', __FILE__)
|
11
|
+
|
12
|
+
# curl -s --user 'api:YOUR_API_KEY' \
|
13
|
+
# https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
|
14
|
+
# -F from='Excited User <mailgun@YOUR_DOMAIN_NAME>' \
|
15
|
+
# -F to=YOU@YOUR_DOMAIN_NAME \
|
16
|
+
# -F to=bar@example.com \
|
17
|
+
# -F subject='Hello' \
|
18
|
+
# -F text='Testing some Mailgun awesomness!'
|
19
|
+
|
20
|
+
def initialize(email)
|
21
|
+
@email = email
|
22
|
+
@template = ERB.new(File.read(HTML_TEMPLATE))
|
23
|
+
end
|
24
|
+
|
25
|
+
def notify(item)
|
26
|
+
b = binding
|
27
|
+
b.local_variable_set(:item, item)
|
28
|
+
html = @template.result(b)
|
29
|
+
puts "-------"
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
"<Adapter::Email email=#{email}>"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'http'
|
2
|
+
require 'oj'
|
3
|
+
|
4
|
+
module RssNotifier
|
5
|
+
module Adapter
|
6
|
+
class Pushbullet
|
7
|
+
|
8
|
+
attr_reader :name
|
9
|
+
attr_reader :access_token
|
10
|
+
|
11
|
+
def initialize(name, access_token)
|
12
|
+
@name = name
|
13
|
+
@access_token = access_token
|
14
|
+
end
|
15
|
+
|
16
|
+
def notify(item)
|
17
|
+
body = Oj.dump({
|
18
|
+
'type' => 'link',
|
19
|
+
'title' => "#{item.rss_title}",
|
20
|
+
'body' => item.title,
|
21
|
+
'url' => item.link
|
22
|
+
})
|
23
|
+
|
24
|
+
RssNotifier.logger.debug("Adapter::Pushbullet #{name}, #{body}")
|
25
|
+
|
26
|
+
response = HTTP.timeout(:per_operation, write: 5, connect: 7, read: 5)
|
27
|
+
.headers(
|
28
|
+
'Access-Token' => access_token,
|
29
|
+
'Content-Type' => 'application/json'
|
30
|
+
)
|
31
|
+
.post('https://api.pushbullet.com/v2/pushes', body: body)
|
32
|
+
|
33
|
+
if response.code != 200
|
34
|
+
RssNotifier.logger.warn("Could not notify #{self}. Code=#{response.code}")
|
35
|
+
false
|
36
|
+
else
|
37
|
+
RssNotifier.logger.debug("#{self} notified")
|
38
|
+
true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
"<Adapter::Pushbullet #{name}>"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'rss_notifier/adapter'
|
2
|
+
require 'rss_notifier/config'
|
3
|
+
require 'rss_notifier/db'
|
4
|
+
require 'rss_notifier/item'
|
5
|
+
|
6
|
+
require 'pathname'
|
7
|
+
require 'rss'
|
8
|
+
require 'http'
|
9
|
+
|
10
|
+
require 'pry'
|
11
|
+
|
12
|
+
module RssNotifier
|
13
|
+
class App
|
14
|
+
|
15
|
+
CONFIG_DIR = Pathname.new('.')
|
16
|
+
CONFIG_FILE = CONFIG_DIR.join('config.yml')
|
17
|
+
DB_FILE = CONFIG_DIR.join('db.yml')
|
18
|
+
|
19
|
+
|
20
|
+
attr_reader :options
|
21
|
+
|
22
|
+
|
23
|
+
def self.init(force: false)
|
24
|
+
if !Dir.exists?(CONFIG_DIR.to_s) || force
|
25
|
+
RssNotifier.logger.info("Creating #{CONFIG_DIR}")
|
26
|
+
FileUtils.mkdir_p(CONFIG_DIR.to_s)
|
27
|
+
else
|
28
|
+
RssNotifier.logger.info("Directory #{CONFIG_DIR} already exists, skipping")
|
29
|
+
end
|
30
|
+
|
31
|
+
if !File.exists?(CONFIG_FILE) || force
|
32
|
+
RssNotifier.logger.info("Creating #{CONFIG_FILE}")
|
33
|
+
config = RssNotifier::Config.default
|
34
|
+
config.save_to(CONFIG_FILE)
|
35
|
+
else
|
36
|
+
RssNotifier.logger.info("File #{CONFIG_FILE} already exists, skipping")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize(notify: false)
|
41
|
+
@config = RssNotifier::Config.load(CONFIG_FILE)
|
42
|
+
@db = RssNotifier::Db.load(DB_FILE)
|
43
|
+
@notify = []
|
44
|
+
@options = {
|
45
|
+
notify: notify
|
46
|
+
}
|
47
|
+
|
48
|
+
setup_notify(@config.notify)
|
49
|
+
end
|
50
|
+
|
51
|
+
def setup_notify(notify)
|
52
|
+
notify.each do |d|
|
53
|
+
next unless d[:enabled]
|
54
|
+
if d[:adapter] == 'email'
|
55
|
+
@notify << Adapter::Email.new(d[:email])
|
56
|
+
elsif d[:adapter] == 'pushbullet'
|
57
|
+
@notify << Adapter::Pushbullet.new(d[:name], d[:access_token])
|
58
|
+
else
|
59
|
+
raise "Unknown adapter #{d[:adapter]}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def run
|
65
|
+
loop do
|
66
|
+
check_rss!
|
67
|
+
sleep @config.period_in_minutes * 60
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def check_rss!
|
72
|
+
RssNotifier.logger.info "Checking #{@config.rss_urls.size} urls"
|
73
|
+
|
74
|
+
@config.rss_urls.each do |url_object|
|
75
|
+
title, url = url_object[:title], url_object[:url]
|
76
|
+
raw = HTTP.get(url).to_s
|
77
|
+
feed = RSS::Parser.parse(raw)
|
78
|
+
items = []
|
79
|
+
feed.items.each do |item|
|
80
|
+
items << Item.new({
|
81
|
+
rss_url: url,
|
82
|
+
rss_title: title,
|
83
|
+
link: item.link,
|
84
|
+
title: item.title,
|
85
|
+
description: item.description,
|
86
|
+
date: item.date
|
87
|
+
})
|
88
|
+
end
|
89
|
+
@db.update(items)
|
90
|
+
end
|
91
|
+
changed_items = @db.changed_items
|
92
|
+
is_changed = @db.changed?
|
93
|
+
@db.save
|
94
|
+
|
95
|
+
unless is_changed
|
96
|
+
RssNotifier.logger.info 'No changes'
|
97
|
+
return
|
98
|
+
end
|
99
|
+
|
100
|
+
if options[:notify]
|
101
|
+
RssNotifier.logger.info "#{changed_items.size} items changed, notifing..."
|
102
|
+
|
103
|
+
changed_items.each do |item|
|
104
|
+
notify!(item)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def notify!(item)
|
110
|
+
@notify.each do |notify|
|
111
|
+
begin
|
112
|
+
notify.notify(item)
|
113
|
+
rescue => e
|
114
|
+
puts "#{e}: #{item.link} | #{notify}"
|
115
|
+
puts e.backtrace
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module RssNotifier
|
4
|
+
class Cli < Thor
|
5
|
+
|
6
|
+
package_name 'RssNotifier'
|
7
|
+
|
8
|
+
desc "init", "Initializes the app"
|
9
|
+
method_options :force => :boolean, :notify => :boolean
|
10
|
+
def init
|
11
|
+
RssNotifier::App.init(force: options.force?)
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "start", "starts the app"
|
15
|
+
method_options :notify => :boolean
|
16
|
+
def start
|
17
|
+
unless options.notify?
|
18
|
+
RssNotifier.logger.warn "Notifcation is disabled. To enable, run $ rss_notifier start --notify"
|
19
|
+
end
|
20
|
+
|
21
|
+
app = RssNotifier::App.new(notify: options.notify?)
|
22
|
+
app.run
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module RssNotifier
|
5
|
+
class Config < OpenStruct
|
6
|
+
|
7
|
+
DEFAULTS = {
|
8
|
+
adapters: {
|
9
|
+
email: {
|
10
|
+
mailgun_api: 'something',
|
11
|
+
from: 'Excited User <mailgun@YOUR_DOMAIN_NAME>'
|
12
|
+
}
|
13
|
+
},
|
14
|
+
notify: [
|
15
|
+
{ email: 'me@example.com', adapter: 'email', enabled: false },
|
16
|
+
{ name: 'mini me', access_token: '<get from pushbullet.com/#settings>', adapter: 'pushbullet', enabled: false },
|
17
|
+
],
|
18
|
+
rss_urls: [
|
19
|
+
{ title: 'Some News', url: 'http://some-site.com/rss' }
|
20
|
+
],
|
21
|
+
period_in_minutes: 20
|
22
|
+
}
|
23
|
+
|
24
|
+
def self.load(filename)
|
25
|
+
c = YAML.load(File.read(filename))
|
26
|
+
RssNotifier::Config.new(DEFAULTS.dup.merge(c['rss_notifier'] || c[:rss_notifier]))
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.default
|
30
|
+
RssNotifier::Config.new(DEFAULTS)
|
31
|
+
end
|
32
|
+
|
33
|
+
def save_to(filename)
|
34
|
+
File.open(filename, 'w') do |f|
|
35
|
+
f.write(YAML.dump({ rss_notifier: self.to_h }))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'yaml/store'
|
2
|
+
# require 'pstore'
|
3
|
+
|
4
|
+
module RssNotifier
|
5
|
+
class Db
|
6
|
+
|
7
|
+
attr_reader :store
|
8
|
+
attr_accessor :items
|
9
|
+
|
10
|
+
|
11
|
+
def initialize(store)
|
12
|
+
# { item_url => Item, ... }
|
13
|
+
@items = {}
|
14
|
+
@store = store
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param url [String]
|
18
|
+
# @param items [Array] of Item
|
19
|
+
# @return [Boolean] changed?
|
20
|
+
def update(new_items)
|
21
|
+
new_items.each do |item|
|
22
|
+
if !item.link || item.link.empty?
|
23
|
+
RssNotifier.logger.warn "Empty item_url for url #{item.link}"
|
24
|
+
next
|
25
|
+
end
|
26
|
+
|
27
|
+
old_item = self.items[item.link] ||= Item.new
|
28
|
+
old_item.update(item.to_h)
|
29
|
+
end
|
30
|
+
changed?
|
31
|
+
end
|
32
|
+
|
33
|
+
def changed?
|
34
|
+
0 < changed_items.size
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Array] of Item
|
38
|
+
def changed_items
|
39
|
+
ch_items = []
|
40
|
+
@items.each do |url, item|
|
41
|
+
if item.new_record? || item.changed?
|
42
|
+
ch_items << item
|
43
|
+
end
|
44
|
+
end
|
45
|
+
ch_items
|
46
|
+
end
|
47
|
+
|
48
|
+
def save
|
49
|
+
return true unless changed?
|
50
|
+
|
51
|
+
@items.each do |url, item|
|
52
|
+
item.saved_at = Time.now
|
53
|
+
end
|
54
|
+
store.transaction do
|
55
|
+
store['items'] = @items
|
56
|
+
end
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.load(filename)
|
61
|
+
store = YAML::Store.new(filename)
|
62
|
+
# store = PStore.new(filename)
|
63
|
+
db = RssNotifier::Db.new(store)
|
64
|
+
store.transaction do
|
65
|
+
db.items = store['items'] || {}
|
66
|
+
end
|
67
|
+
db
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module RssNotifier
|
2
|
+
class Item
|
3
|
+
DONT_SAVE = [ '@is_changed' ]
|
4
|
+
|
5
|
+
attr_accessor :rss_url
|
6
|
+
attr_accessor :rss_title
|
7
|
+
attr_accessor :link
|
8
|
+
attr_accessor :title
|
9
|
+
attr_accessor :description
|
10
|
+
attr_accessor :date
|
11
|
+
attr_accessor :saved_at
|
12
|
+
|
13
|
+
attr_accessor :is_changed
|
14
|
+
|
15
|
+
|
16
|
+
def initialize(params = nil)
|
17
|
+
params and params.each do |k, v|
|
18
|
+
self.send("#{k}=", v)
|
19
|
+
end
|
20
|
+
self.is_changed = true
|
21
|
+
end
|
22
|
+
|
23
|
+
def update(params)
|
24
|
+
self.is_changed = false
|
25
|
+
params.each do |k, v|
|
26
|
+
self.is_changed ||= send(k) != v
|
27
|
+
send("#{k}=", v)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def changed?
|
32
|
+
self.is_changed
|
33
|
+
end
|
34
|
+
|
35
|
+
def new_record?
|
36
|
+
!self.saved_at
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_h
|
40
|
+
{
|
41
|
+
rss_url: rss_url,
|
42
|
+
rss_title: rss_title,
|
43
|
+
link: link,
|
44
|
+
title: title,
|
45
|
+
description: description,
|
46
|
+
date: date,
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def encode_with(coder)
|
51
|
+
vars = instance_variables.map { |x| x.to_s } - DONT_SAVE
|
52
|
+
|
53
|
+
vars.each do |var|
|
54
|
+
var_val = eval(var)
|
55
|
+
coder[var.gsub('@', '')] = var_val
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rss_notifier/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rss_notifier"
|
8
|
+
spec.version = RssNotifier::VERSION
|
9
|
+
spec.authors = ["Zhomart Mukhamejanov"]
|
10
|
+
spec.email = ["mzhomart@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Notifies you when RSS updates via Pushbullet and Email}
|
13
|
+
spec.description = %q{RSS notification}
|
14
|
+
spec.homepage = "https://github.com/Zhomart/rss_notifier"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "bin"
|
19
|
+
spec.executables = spec.files.grep(%r[^bin/]).map { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'nokogiri', '~> 1.6.7.2'
|
23
|
+
spec.add_dependency 'http', '~> 1.0.2'
|
24
|
+
spec.add_dependency 'thor', '~> 0.19.1'
|
25
|
+
spec.add_dependency 'oj', '~> 2.14.5'
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
30
|
+
spec.add_development_dependency "pry", '~> 0.10.3'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rss_notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zhomart Mukhamejanov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.7.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.7.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: http
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.19.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.19.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: oj
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.14.5
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.14.5
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.11'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.11'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '5.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '5.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.10.3
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.10.3
|
125
|
+
description: RSS notification
|
126
|
+
email:
|
127
|
+
- mzhomart@gmail.com
|
128
|
+
executables:
|
129
|
+
- rss_notifier
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CODE_OF_CONDUCT.md
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/rss_notifier
|
141
|
+
- lib/rss_notifier.rb
|
142
|
+
- lib/rss_notifier/adapter.rb
|
143
|
+
- lib/rss_notifier/adapter/email.html.erb
|
144
|
+
- lib/rss_notifier/adapter/email.rb
|
145
|
+
- lib/rss_notifier/adapter/pushbullet.rb
|
146
|
+
- lib/rss_notifier/app.rb
|
147
|
+
- lib/rss_notifier/cli.rb
|
148
|
+
- lib/rss_notifier/config.rb
|
149
|
+
- lib/rss_notifier/db.rb
|
150
|
+
- lib/rss_notifier/item.rb
|
151
|
+
- lib/rss_notifier/version.rb
|
152
|
+
- rss_notifier.gemspec
|
153
|
+
homepage: https://github.com/Zhomart/rss_notifier
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
metadata: {}
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.5.1
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: Notifies you when RSS updates via Pushbullet and Email
|
177
|
+
test_files: []
|
178
|
+
has_rdoc:
|