rss_items_notifier 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b19d4b2762857cdd5c6f8665ca665c236b88e2c
4
+ data.tar.gz: 5d15b6768da677dd32a6b64283182ff81cb8ecbd
5
+ SHA512:
6
+ metadata.gz: '08f8c44c98e8e62eeefe71106d78b6c26c329553d90de2ced18a5a369b35c21dd412bf661b61d695eeadc1bf45a76c32988192085eede8ea168c044fd090f7b7'
7
+ data.tar.gz: 13b935373ec237b76529fce4c8182d02fde2431634ad98de14ad0d49d5ff648116f6198f1239b7881ee1efd6cf8a5fc5d6c060646b2ccf6f797b81ae6828206e
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rss_items_notifier'
4
+ require 'optparse'
5
+ require 'json'
6
+
7
+ check_timer = 5
8
+ rss_url_arg = nil
9
+ state_file_arg = nil
10
+
11
+ OptionParser.new do |opts|
12
+ opts.banner = 'Usage: rss_items_notifier [options]'
13
+
14
+ opts.on('-u', '--url URL', 'Specify rss url for getting new items') do |url|
15
+ rss_url_arg = url
16
+ end
17
+
18
+ opts.on('-t', '--timer TIMER', 'Specify rss new items check period') do |timer|
19
+ check_timer = timer.to_i
20
+ end
21
+
22
+ opts.on('-s', '--state_file_arg FILE', 'Specify state file') do |file|
23
+ state_file_arg = file
24
+ end
25
+
26
+ opts.separator ''
27
+ opts.separator 'Common options:'
28
+
29
+ opts.on_tail('-h', '--help', 'Show this message') do
30
+ puts opts
31
+ exit
32
+ end
33
+
34
+ opts.on_tail('--version', 'Show version') do
35
+ puts RssItemsNotifier::VERSION
36
+ exit
37
+ end
38
+
39
+ end.parse!
40
+
41
+ abort('You must specify rss url') unless rss_url_arg
42
+
43
+ listener = RssItemsNotifier::Listener.new rss_url: rss_url_arg,
44
+ state_file: state_file_arg,
45
+ rss_open_properties: { ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE }
46
+
47
+
48
+ loop do
49
+ listener.obtain_new_items do |item|
50
+ puts item
51
+ end
52
+ listener.save
53
+ sleep check_timer
54
+ end
@@ -0,0 +1,58 @@
1
+ require 'open-uri'
2
+ require 'openssl'
3
+ require 'zlib'
4
+ require 'set'
5
+ require 'rss'
6
+ require 'fileutils'
7
+
8
+ module RssItemsNotifier
9
+
10
+ class Listener
11
+ attr_accessor :name
12
+
13
+ def initialize(settings)
14
+ @crc_feeds = Set.new
15
+ @rss_url = settings[:rss_url]
16
+ @rss_open_properties = settings[:rss_open_properties]
17
+ @name = settings[:name] || @rss_url
18
+ @state_file = settings[:state_file]
19
+
20
+ load
21
+ end
22
+
23
+ def obtain_new_items
24
+ new_crc_feeds = Set.new
25
+ open(@rss_url, @rss_open_properties) do |rss|
26
+ feed = RSS::Parser.parse(rss)
27
+ feed.items.each do |item|
28
+ feed_crc = Zlib::crc32(item.link).to_i
29
+ new_crc_feeds.add feed_crc
30
+ yield item unless @crc_feeds.include?(feed_crc)
31
+ end
32
+ end
33
+ @crc_feeds = new_crc_feeds unless new_crc_feeds.empty?
34
+ end
35
+
36
+ def save
37
+ if @state_file then
38
+ File.open(@state_file, 'w+') do |f|
39
+ f.puts(@crc_feeds.to_a)
40
+ end
41
+ end
42
+ end
43
+
44
+ protected
45
+
46
+ def load
47
+ if @state_file then
48
+ FileUtils.touch @state_file
49
+ File.open(@state_file, 'r+') do |f|
50
+ f.each_line do |line|
51
+ @crc_feeds.add line.to_i
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rss_items_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mikhail Milovidov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Create RssNotifier::Listener for your targets or use rss_items_notifier
14
+ application!
15
+ email: mikhailmilovidov@gmail.com
16
+ executables:
17
+ - rss_items_notifier
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/rss_items_notifier
22
+ - lib/rss_items_notifier.rb
23
+ homepage: https://github.com/milovidov/rss_items_notifier
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.6.13
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Simple ruby gem for notification about new items in rss feed
47
+ test_files: []