newly 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store ADDED
Binary file
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Add dependencies required to use your gem here.
4
+ # Example:
5
+ # gem "activesupport", ">= 2.3.5"
6
+ gem 'nokogiri'
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "rspec", "~> 2.8.0"
12
+ gem "rdoc", "~> 3.12"
13
+ gem "bundler", "~> 1.1.5"
14
+ gem "jeweler", "~> 1.8.4"
15
+ gem "simplecov"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.8.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rdoc
11
+ json (1.7.4)
12
+ multi_json (1.3.6)
13
+ nokogiri (1.5.5)
14
+ rake (0.9.2.2)
15
+ rdoc (3.12)
16
+ json (~> 1.4)
17
+ rspec (2.8.0)
18
+ rspec-core (~> 2.8.0)
19
+ rspec-expectations (~> 2.8.0)
20
+ rspec-mocks (~> 2.8.0)
21
+ rspec-core (2.8.0)
22
+ rspec-expectations (2.8.0)
23
+ diff-lcs (~> 1.1.2)
24
+ rspec-mocks (2.8.0)
25
+ simplecov (0.6.4)
26
+ multi_json (~> 1.0)
27
+ simplecov-html (~> 0.5.3)
28
+ simplecov-html (0.5.3)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.1.5)
35
+ jeweler (~> 1.8.4)
36
+ nokogiri
37
+ rdoc (~> 3.12)
38
+ rspec (~> 2.8.0)
39
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2012 Alabê Duarte
2
+ Twitter: @alabeduarte
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,31 @@
1
+ = newly
2
+
3
+ Fetching breaking news from websites
4
+
5
+ == SYNOPSIS:
6
+
7
+ #Fecthing breaking news from some website
8
+ reader = Newly.new('http://g1.globo.com/bahia/')
9
+ news = reader.highlights(css: '#ultimas-regiao div, #ultimas-regiao ul li',
10
+ url: 'a',
11
+ date: '.data-hora',
12
+ title: '.titulo',
13
+ subtitle: '.subtitulo',
14
+ image: 'img'
15
+ )
16
+
17
+ == Contributing to newly
18
+
19
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
20
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
21
+ * Fork the project.
22
+ * Start a feature/bugfix branch.
23
+ * Commit and push until you are happy with your contribution.
24
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
25
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
26
+
27
+ == Copyright
28
+
29
+ Copyright (c) 2012 Alabê Duarte. See LICENSE.txt for
30
+ further details.
31
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "newly"
18
+ gem.homepage = "http://github.com/alabeduarte/newly"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Fetching breaking news from websites}
21
+ gem.description = %Q{Fetching breaking news from websites}
22
+ gem.email = "alabeduarte@gmail.com"
23
+ gem.authors = ["Alabê Duarte"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "newly #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/newly.rb ADDED
@@ -0,0 +1,58 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'news'
4
+
5
+ class Newly
6
+
7
+ attr_reader :title, :selector, :url
8
+
9
+ def initialize(url, html_file=nil)
10
+ @url = url
11
+ if (html_file)
12
+ @selector = Nokogiri::HTML.parse(File.read(html_file))
13
+ else
14
+ @selector = Nokogiri::HTML(open(url))
15
+ end
16
+ @title = @selector.at_css("title").text
17
+ end
18
+
19
+ def fetch(args)
20
+ array = Array.new
21
+ @selector.css(args[:css]).each do |item|
22
+ if (item)
23
+ if (args[:property].nil?)
24
+ array << item.css(args[:tag]).text
25
+ else
26
+ array << item.css(args[:tag]).map { |doc| doc[args[:property]] }.first
27
+ end
28
+ end
29
+ end
30
+ array
31
+ end
32
+
33
+ def highlights(args)
34
+ news = Array.new
35
+ @selector.css(args[:css]).each do |item|
36
+ if (item)
37
+ url = item.css(args[:url]).map { |doc| doc['href'] }.first if args[:url]
38
+
39
+ # doc = Nokogiri::HTML(open(url))
40
+ # keywords = doc.xpath("//meta[@name='Keywords']/@content") if doc
41
+ keywords = nil
42
+
43
+ date = item.css(args[:date]).text if args[:date]
44
+ title = item.css(args[:title]).text if args[:title]
45
+ subtitle = item.css(args[:subtitle]).text if args[:subtitle]
46
+ image = item.css(args[:image]).map { |doc| doc['src'] }.first if args[:image]
47
+ if (args[:host])
48
+ host = args[:host]
49
+ url = "#{host}/#{url}".gsub('../', '') if url
50
+ image = "#{host}/#{image}".gsub('../', '') if image && image.include?('../')
51
+ end
52
+ news << News.new(url: url, keywords: keywords, date: date, title: title, subtitle: subtitle, image: image)
53
+ end
54
+ end
55
+ news
56
+ end
57
+
58
+ end
data/lib/news.rb ADDED
@@ -0,0 +1,12 @@
1
+ class News
2
+ attr_reader :url, :date, :title, :subtitle, :image
3
+
4
+ def initialize(args)
5
+ @url = args[:url]
6
+ @keywords = args[:keywords]
7
+ @date = args[:date]
8
+ @title = args[:title]
9
+ @subtitle = args[:subtitle]
10
+ @image = args[:image]
11
+ end
12
+ end
data/newly.gemspec ADDED
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "newly"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alab\u{ea} Duarte"]
12
+ s.date = "2012-08-13"
13
+ s.description = "Fetching breaking news from websites"
14
+ s.email = "alabeduarte@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".DS_Store",
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/newly.rb",
30
+ "lib/news.rb",
31
+ "newly.gemspec",
32
+ "spec/.DS_Store",
33
+ "spec/html/ecbahia.html",
34
+ "spec/html/g1.html",
35
+ "spec/html/g1_bahia.html",
36
+ "spec/html/metro1_cidade.html",
37
+ "spec/newly_spec.rb",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+ s.homepage = "http://github.com/alabeduarte/newly"
41
+ s.licenses = ["MIT"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = "1.8.10"
44
+ s.summary = "Fetching breaking news from websites"
45
+
46
+ if s.respond_to? :specification_version then
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
51
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
52
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
53
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.5"])
54
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
55
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
56
+ else
57
+ s.add_dependency(%q<nokogiri>, [">= 0"])
58
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
59
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.1.5"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
62
+ s.add_dependency(%q<simplecov>, [">= 0"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<nokogiri>, [">= 0"])
66
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
67
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
68
+ s.add_dependency(%q<bundler>, ["~> 1.1.5"])
69
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
70
+ s.add_dependency(%q<simplecov>, [">= 0"])
71
+ end
72
+ end
73
+
data/spec/.DS_Store ADDED
Binary file