rarch_news 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: e42335e027536f597fab0b9af9d7cd0a809a6c9d
4
+ data.tar.gz: 806a40b0e82d46564059e36f05d9292d094fff0c
5
+ SHA512:
6
+ metadata.gz: 386aa12438a01a92bbfe8a1ffc2a737748dd57be42028a7f1fd7ad44005f2bbbb74d31119cfb6d193ec77689dd86375f7e9aab6489cdc497da7ddfb015e4f0c0
7
+ data.tar.gz: 795bb072f11d81e196c679c213c9627350f52a65cce1e2fe40fa7becc5b84bdc3c51552084b6ed0484d868f1360d42f0299dc7fd1d938fea1f2a91f81592abf9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Ahmed Khaled
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,32 @@
1
+ # RarchNews
2
+ RarchNews is a **Ruby** gem written to help **Arch Linux** by notifying them _(with various methods)_ of the news written on the Arch Linux website, which we sometimes forget to check it regulary.
3
+ This gem was meant to be run on schedule, that's why I decided to use - our lovely! - **Systemd Timers** to put it on schedule.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ $ yaours -S rarch_news
9
+ ```
10
+
11
+
12
+ ## Usage
13
+
14
+ This gem provides a very simple straightforward api to fetch Arch Linux news by reading its RSS feed. To use it add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'rarch_news'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ ## Contributing
25
+
26
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nemoload/rarch_news.
27
+
28
+
29
+ ## License
30
+
31
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
32
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rarch_news"
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__)
data/bin/setup ADDED
@@ -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
data/exe/rarch_news ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rarch_news'
5
+ require 'rlps'
6
+
7
+ articles = RarchNews.articles
8
+ articles.at(2).save! if RarchNews.first_run?
9
+ last_article = RarchNews::Article.last_article
10
+
11
+ unread_articles = articles.select { |a| a > last_article }
12
+ unread_articles.each do |a|
13
+ unless RLPS.processes.select do |p|
14
+ p.name.casecmp('xorg').zero? ||
15
+ p.name.casecmp('wayland').zero?
16
+ end.empty?
17
+ require 'libnotify'
18
+ Libnotify.show(body: a.description.slice(0..140), summary: "RarchNews: #{a.title}", timeout: 10)
19
+ end
20
+ # TODO sendmail
21
+
22
+ end
23
+ unread_articles.first.save! unless unread_articles.empty?
@@ -0,0 +1,39 @@
1
+ require 'yaml'
2
+
3
+ require 'rarch_news/date'
4
+
5
+ module RarchNews
6
+ class Article
7
+ attr_accessor :title, :link, :description, :creator, :pub_date
8
+ include Comparable
9
+ def initialize(title, link, description, creator, pub_date)
10
+ # def initialize(title, link, description, creator, pub_date,*options)
11
+ # raise "Unexpected arguments" unless options.length == 4 or options.length == 0
12
+ @title = title
13
+ @link = link
14
+ @description = description
15
+ @creator = creator
16
+ @pub_date = Date.archdate pub_date # unless pub_date.is_a? DateTime
17
+ end
18
+
19
+ def to_s
20
+ "#{@title} <By: #{@creator}. At: #{@pub_date}>\n#{@link}\n#{@description}"
21
+ end
22
+
23
+ def <=>(other)
24
+ @pub_date <=> other.pub_date
25
+ end
26
+
27
+ def save!
28
+ File.open File.join(RarchNews.configuration.path, RarchNews.configuration.last_article), 'w' do |file|
29
+ file.puts YAML.dump self
30
+ end
31
+ end
32
+
33
+ def self.last_article
34
+ # return nil unless File.exist? File.join(RarchNews.configuration.path,RarchNews.configuration.name)
35
+ return nil if RarchNews.first_run? # TODO raise something
36
+ YAML.load_file(File.join(RarchNews.configuration.path, RarchNews.configuration.last_article))
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ module RarchNews
2
+ class Configuration
3
+ attr_accessor :url, :path, :last_article, :mail, :config_dir
4
+ def initialize
5
+ @config_dir = File.join '.config', 'rarch_news'
6
+ @path = File.expand_path @config_dir, Dir.home
7
+ Dir.mkdir @path unless File.exist? @path
8
+ @url = 'https://www.archlinux.org/feeds/news/'
9
+ @last_article = 'last_article.yaml'
10
+ # @mail = 'mail.yaml'
11
+ end
12
+
13
+ # def mail_config; end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ require 'date'
2
+ module RarchNews
3
+ class Date
4
+ def self.archdate(pub_date)
5
+ DateTime.parse pub_date.gsub(/ \+\d*$/, '')
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,33 @@
1
+ # require 'pony'
2
+ #
3
+ # module RarchNews
4
+ # module Mail
5
+ # def send_mail
6
+ # mail = load_mail_settings
7
+ #
8
+ # Pony.mail(to: 'you@example.com',
9
+ # via: :smtp,
10
+ # via_options: {
11
+ # address: 'smtp.gmail.com',
12
+ # port: '587',
13
+ # enable_starttls_auto: true,
14
+ # user_name: 'user',
15
+ # password: 'password_see_note',
16
+ # authentication: :plain, # :plain, :login, :cram_md5, no auth by default
17
+ # domain: 'localhost.localdomain' # the HELO domain provided by the client to the server
18
+ # })
19
+ # end
20
+ #
21
+ # private
22
+ #
23
+ # def self.load_mail_settings
24
+ # if File.exist? File.expand_path RarchNews.configuration.path, RarchNews.configuration.mail
25
+ # YAML.load_file(File.join(RarchNews.configuration.path, RarchNews.configuration.last_article))
26
+ # end
27
+ # nil
28
+ # end
29
+ #
30
+ # def gmail
31
+ # end
32
+ # end
33
+ # end
@@ -0,0 +1,3 @@
1
+ module RarchNews
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ module RarchNews
5
+ class XML
6
+ attr_reader :articles
7
+ def initialize(url = RarchNews.configuration.url)
8
+ doc = Nokogiri::XML open(url)
9
+ @articles = doc.css 'item'
10
+ end
11
+ end
12
+ end
data/lib/rarch_news.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'nokogiri'
2
+
3
+ require 'rarch_news/version'
4
+ require 'rarch_news/xml'
5
+ require 'rarch_news/article'
6
+ require 'rarch_news/configuration'
7
+
8
+ module RarchNews
9
+ class << self
10
+ attr_accessor :configuration
11
+ end
12
+
13
+ module_function
14
+
15
+ def configure
16
+ yield configuration
17
+ end
18
+
19
+ def configuration
20
+ @configuration ||= RarchNews::Configuration.new
21
+ end
22
+
23
+ def articles
24
+ articles = RarchNews::XML.new.articles
25
+ articles_arr = []
26
+ articles.each do |article|
27
+
28
+ title = article.css('title').text
29
+ link = article.css('link').text
30
+ description = article.css('description').text.gsub(/<\/?[^>]+>/, '')
31
+ creator = article.css('creator').text
32
+ pubDate = article.css('pubDate').text
33
+
34
+ new_article = RarchNews::Article.new title, link,description,creator,pubDate
35
+ yield new_article if block_given?
36
+ articles_arr << new_article
37
+ end
38
+ articles_arr
39
+ end
40
+
41
+ def first_run?
42
+ !File.exist? File.join configuration.path, configuration.last_article
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rarch_news/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rarch_news'
8
+ spec.version = RarchNews::VERSION
9
+ spec.authors = ['Ahmed Khaled']
10
+ spec.email = ['nemoload@aol.com']
11
+
12
+ spec.summary = 'Get ArchLinux website news.'
13
+ spec.description = 'This Ruby Gem is created mainly to be called from a\
14
+ cron job to notify Arch Linux user of the updates \
15
+ and news written in Arch Linux webiste.'
16
+ spec.homepage = 'https://nemoload.github.io'
17
+ spec.license = 'MIT'
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ # if spec.respond_to?(:metadata)
22
+ # spec.metadata['allowed_push_host'] = "Set to 'http://mygemserver.com'"
23
+ # else
24
+ # raise "RubyGems 2.0 or newer is required to protect against " \
25
+ # "public gem pushes."
26
+ # end
27
+
28
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
29
+ f.match(%r{^(test|spec|features)/})
30
+ end
31
+ spec.bindir = 'exe'
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ['lib']
34
+
35
+ spec.add_runtime_dependency 'nokogiri', '~> 1.7'
36
+ spec.add_runtime_dependency 'rlps'
37
+ spec.add_runtime_dependency 'libnotify', '~> 0.9'
38
+ #spec.add_runtime_dependency 'pony', '~> 1.11'
39
+
40
+ spec.add_development_dependency 'bundler', '~> 1.14'
41
+ spec.add_development_dependency 'rake', '~> 10.0'
42
+ spec.add_development_dependency 'rspec', '~> 3.5'
43
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rarch_news
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ahmed Khaled
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-16 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.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rlps
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: libnotify
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.5'
97
+ description: |-
98
+ This Ruby Gem is created mainly to be called from a\
99
+ cron job to notify Arch Linux user of the updates \
100
+ and news written in Arch Linux webiste.
101
+ email:
102
+ - nemoload@aol.com
103
+ executables:
104
+ - rarch_news
105
+ extensions: []
106
+ extra_rdoc_files: []
107
+ files:
108
+ - ".gitignore"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - exe/rarch_news
116
+ - lib/rarch_news.rb
117
+ - lib/rarch_news/article.rb
118
+ - lib/rarch_news/configuration.rb
119
+ - lib/rarch_news/date.rb
120
+ - lib/rarch_news/mail.rb
121
+ - lib/rarch_news/version.rb
122
+ - lib/rarch_news/xml.rb
123
+ - rarch_news.gemspec
124
+ homepage: https://nemoload.github.io
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.6.8
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Get ArchLinux website news.
148
+ test_files: []