rss_notifier 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/rss_notifier/app.rb +30 -4
- data/lib/rss_notifier/cli.rb +2 -1
- data/lib/rss_notifier/models/feed.rb +2 -6
- data/lib/rss_notifier/version.rb +1 -1
- data/rss_notifier.gemspec +2 -0
- metadata +29 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30348630c71ce8a624dcda3085e681c23888b2db
|
4
|
+
data.tar.gz: 5de199efd8829d5ac06753b6daef97457f32eacc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffb126f61c05742ccef948092f0d016cb29336983114613a5d238ee5b29e1d6ea285284466eafe2cf31d087c93436c6a0f5a8238465211d40fe455cbf28f4ab0
|
7
|
+
data.tar.gz: 91e4ea57ce1661425a3d173a43c9395c25836009d9fe53c31c12aa163287701b1861eee45807d697a4eb789a79509d925d00e23a23b2a655e9e82707c609dc5d
|
data/README.md
CHANGED
@@ -49,16 +49,20 @@ If you want it to run in the background, use `tmux`.
|
|
49
49
|
## Craigslist
|
50
50
|
|
51
51
|
1. Create a search url on craigslist, e.g. http://sfbay.craigslist.org/search/bik?query=trek+520
|
52
|
-
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
|
52
|
+
2. Make it RSS by clicking orange button `RSS` on the bottom-right of the page, e.g. https://sfbay.craigslist.org/search/bik?format=rss&query=trek%20520
|
53
53
|
3. Install gem and initialize it.
|
54
54
|
4. Add RSS link to the `config.yml`.
|
55
|
-
5. Start
|
55
|
+
5. Start without notification: `$ rss_notifier start`, other you'll flood your inbox.
|
56
|
+
6. Start with notification: `$ rss_notifier start --notify`. I use `tmux` to run it in the background.
|
56
57
|
|
57
58
|
|
58
59
|
## Development
|
59
60
|
|
60
61
|
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).
|
61
62
|
|
63
|
+
## TODO
|
64
|
+
|
65
|
+
- Add cache handling
|
62
66
|
|
63
67
|
## Contributing
|
64
68
|
|
data/lib/rss_notifier/app.rb
CHANGED
@@ -6,6 +6,7 @@ require 'rss_notifier/models'
|
|
6
6
|
require 'pathname'
|
7
7
|
require 'rss'
|
8
8
|
require 'http'
|
9
|
+
require 'htmlentities'
|
9
10
|
|
10
11
|
module RssNotifier
|
11
12
|
class App
|
@@ -42,6 +43,7 @@ module RssNotifier
|
|
42
43
|
@options = {
|
43
44
|
notify: notify
|
44
45
|
}
|
46
|
+
@html_coder = HTMLEntities.new
|
45
47
|
|
46
48
|
setup_notify(@config.notify)
|
47
49
|
end
|
@@ -85,8 +87,25 @@ module RssNotifier
|
|
85
87
|
rss_raw = nil
|
86
88
|
response = nil
|
87
89
|
begin
|
88
|
-
|
89
|
-
#
|
90
|
+
headers = {}
|
91
|
+
max_cache_duration = 20*60 # 20 minutes
|
92
|
+
if feed.last_modified
|
93
|
+
headers['If-Modified-Since'] = feed.last_modified.utc.httpdate
|
94
|
+
end
|
95
|
+
headers['Cache-Control'] = 'no-cache'
|
96
|
+
response = HTTP.headers(headers).get(url)
|
97
|
+
|
98
|
+
if response.code == 304
|
99
|
+
RssNotifier.logger.info "Not modified since #{feed.last_modified}: #{name} | #{url}"
|
100
|
+
next
|
101
|
+
elsif response.code != 200
|
102
|
+
RssNotifier.logger.warn "got non 200 code: #{response.code}:"
|
103
|
+
puts response.body.to_s
|
104
|
+
next
|
105
|
+
end
|
106
|
+
|
107
|
+
feed.last_modified = Time.parse(response.headers['Last-Modified'])
|
108
|
+
|
90
109
|
raw_encoded = response.to_s.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
|
91
110
|
rss_raw = RSS::Parser.parse(raw_encoded)
|
92
111
|
rescue => e
|
@@ -94,11 +113,12 @@ module RssNotifier
|
|
94
113
|
puts e.backtrace
|
95
114
|
next
|
96
115
|
end
|
116
|
+
|
97
117
|
rss_raw.items.each do |raw_item|
|
98
118
|
item = feed.find_or_create_item(link: raw_item.link)
|
99
119
|
item.update({
|
100
|
-
title: raw_item.title,
|
101
|
-
description: raw_item.description,
|
120
|
+
title: decode_html(raw_item.title),
|
121
|
+
description: decode_html(raw_item.description),
|
102
122
|
date: raw_item.date
|
103
123
|
})
|
104
124
|
changed_items << item if item.changed?
|
@@ -123,6 +143,12 @@ module RssNotifier
|
|
123
143
|
end
|
124
144
|
end
|
125
145
|
|
146
|
+
def decode_html(encoded)
|
147
|
+
@html_coder.decode(encoded)
|
148
|
+
rescue => e
|
149
|
+
encoded
|
150
|
+
end
|
151
|
+
|
126
152
|
def notify!(item)
|
127
153
|
@notify.each do |notify|
|
128
154
|
begin
|
data/lib/rss_notifier/cli.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'thor'
|
2
|
+
require 'colorize'
|
2
3
|
|
3
4
|
module RssNotifier
|
4
5
|
class Cli < Thor
|
@@ -20,7 +21,7 @@ module RssNotifier
|
|
20
21
|
method_options :notify => :boolean
|
21
22
|
def start
|
22
23
|
unless options.notify?
|
23
|
-
RssNotifier.logger.warn "Notifcation is disabled. To enable, run $ rss_notifier start --notify"
|
24
|
+
RssNotifier.logger.warn "Notifcation is disabled. To enable, run $ rss_notifier start --notify".red
|
24
25
|
end
|
25
26
|
|
26
27
|
app = RssNotifier::App.new(notify: options.notify?)
|
@@ -2,12 +2,6 @@ require 'virtus'
|
|
2
2
|
require 'inflecto'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
# {
|
6
|
-
# rss_url => {
|
7
|
-
# 'Last-Modified' => 'blah',
|
8
|
-
# 'items' => { item_url => Item, ... },
|
9
|
-
# }
|
10
|
-
# }
|
11
5
|
module RssNotifier
|
12
6
|
module Models
|
13
7
|
class Feed
|
@@ -15,6 +9,7 @@ module RssNotifier
|
|
15
9
|
|
16
10
|
attribute :url, String
|
17
11
|
attribute :name, String
|
12
|
+
attribute :last_modified, Time
|
18
13
|
attribute :items, Array['RssNotifier::Models::Item']
|
19
14
|
|
20
15
|
# updated_at in DB
|
@@ -56,6 +51,7 @@ module RssNotifier
|
|
56
51
|
'url' => url,
|
57
52
|
'name' => name,
|
58
53
|
'updated_at' => updated_at,
|
54
|
+
'last_modified' => last_modified,
|
59
55
|
'items' => items.map(&:to_db_object),
|
60
56
|
}
|
61
57
|
end
|
data/lib/rss_notifier/version.rb
CHANGED
data/rss_notifier.gemspec
CHANGED
@@ -24,6 +24,8 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_dependency 'virtus', '~> 1.0'
|
25
25
|
spec.add_dependency 'inflecto', '~> 0.0'
|
26
26
|
spec.add_dependency 'sendgrid-ruby', '~> 1.1'
|
27
|
+
spec.add_dependency 'htmlentities', '~> 4.3'
|
28
|
+
spec.add_dependency 'colorize', '~> 0.0'
|
27
29
|
|
28
30
|
spec.add_development_dependency "bundler", "~> 1.11"
|
29
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rss_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zhomart Mukhamejanov
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: htmlentities
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.3'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: colorize
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: bundler
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|