rss_watcher 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ffe62440dbb07c9f6dc0a8f3e92063d8830cb3beffb5c71e0db425d7acf599ec
4
+ data.tar.gz: fcb086bbf67e619ef0aca722a9804e5306e1917e71b892ad707c7d80f94e4d09
5
+ SHA512:
6
+ metadata.gz: 7711af450ab72ab3409e8738099841722961f1303e87d38739c828ebba104f3f2f2d93b5927aa924e9198c4240f61ef9df7608e377afa247eb7da6ef9616520f
7
+ data.tar.gz: ffe570172578bfc3e391c8e1af82de1554d7df7adf23fff593d34090e9cacbda25d55becdf7c76abeb5bbab40f3de99000ef73f42a62d49cb15fe7745f291eca
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.5
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rss_watcher.gemspec
6
+ gemspec
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rss_watcher (0.1.0)
5
+ rss (~> 0.2.8)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ minitest (5.14.0)
11
+ rake (10.5.0)
12
+ rss (0.2.8)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.17)
19
+ minitest (~> 5.0)
20
+ rake (~> 10.0)
21
+ rss_watcher!
22
+
23
+ BUNDLED WITH
24
+ 1.17.3
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
@@ -0,0 +1,35 @@
1
+ # RssWatcher
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rss_watcher`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rss_watcher'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rss_watcher
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/owaiswiz/rss_watcher.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rss_watcher"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ require "rss"
2
+ require "open-uri"
3
+ require "rss_watcher/version"
4
+ require "rss_watcher/feed_manager"
5
+
6
+ module RssWatcher
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ def self.watch url:, update_interval: 10, cache_file: "rss_watcher.cache"
10
+ #url - RSS feed url
11
+ #updated_interval - Seconds to wait for between checking for updates to the RSS feed
12
+ #cache_file - Path to a file that this gem uses internally for remembering the last seen item
13
+ while true
14
+ open(url) do |rss|
15
+ feed = RSS::Parser.parse(rss)
16
+ RssWatcher::FeedManager.new(cache_file).get_new_feed_items(feed.items).each do |item|
17
+ yield item if block_given?
18
+ end
19
+ end
20
+ sleep update_interval
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,58 @@
1
+ module RssWatcher
2
+ class FeedManager
3
+ def initialize cache_file_path
4
+ @cache_file_path = cache_file_path
5
+ end
6
+
7
+ def get_new_feed_items feed_items
8
+ load_cache
9
+
10
+ new_feed_items = []
11
+ feed_items = feed_items.sort_by(&:pubDate).reverse
12
+
13
+ feed_items.each do |item|
14
+ break if old_item? item
15
+ new_feed_items << item if new_item? item
16
+ end
17
+
18
+ update_cache feed_items
19
+ dump_cache
20
+
21
+ return new_feed_items.reverse
22
+ end
23
+
24
+ private
25
+ def new_item? item
26
+ item.pubDate.to_i > @cache[:time] || (!old_item?(item) && !item_in_cache?(item))
27
+ end
28
+
29
+ def old_item? item
30
+ item.pubDate.to_i < @cache[:time]
31
+ end
32
+
33
+ def item_in_cache? item
34
+ @cache[:items_title].include? item.title
35
+ end
36
+
37
+ def load_cache
38
+ if File.exists? @cache_file_path
39
+ @cache = Marshal.load File.read(@cache_file_path)
40
+ else
41
+ @cache = {time: Time.now.to_i, items_title: []}
42
+ end
43
+ end
44
+
45
+ def update_cache feed_items
46
+ return if feed_items.length == 0
47
+ most_recent_items = feed_items.group_by(&:pubDate)[feed_items.first.pubDate]
48
+ @cache[:time] = most_recent_items.first.pubDate.to_i
49
+ @cache[:items_title] = most_recent_items.collect &:title
50
+ end
51
+
52
+ def dump_cache
53
+ File.open(@cache_file_path, 'w') do |file|
54
+ file.write Marshal.dump(@cache)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module RssWatcher
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rss_watcher/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rss_watcher"
8
+ spec.version = RssWatcher::VERSION
9
+ spec.authors = ["Owais"]
10
+ spec.email = ["owaiswiz@gmail.com"]
11
+
12
+ spec.summary = %q{A Ruby Gem For Watching RSS Feeds}
13
+ spec.homepage = "https://github.com/owaiswiz/rss_watcher"
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "rss", "~> 0.2.8"
25
+ spec.add_development_dependency "bundler", "~> 1.17"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rss_watcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Owais
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rss
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description:
70
+ email:
71
+ - owaiswiz@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/rss_watcher.rb
86
+ - lib/rss_watcher/feed_manager.rb
87
+ - lib/rss_watcher/version.rb
88
+ - rss_watcher.gemspec
89
+ homepage: https://github.com/owaiswiz/rss_watcher
90
+ licenses: []
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.0.6
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: A Ruby Gem For Watching RSS Feeds
111
+ test_files: []