rogerleite-anvisa-bot 0.2.1 → 0.2.2
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.
- data/{fluxo_site_anvisa.txt → FLUXO_SITE_ANVISA.txt} +0 -0
- data/Rakefile +2 -2
- data/lib/anvisa_bot.rb +11 -7
- data/lib/anvisa_parser.rb +13 -2
- metadata +5 -9
- data/anvisa-bot.gemspec +0 -32
|
File without changes
|
data/Rakefile
CHANGED
|
@@ -5,7 +5,7 @@ require 'rake/gempackagetask'
|
|
|
5
5
|
require 'spec/rake/spectask'
|
|
6
6
|
|
|
7
7
|
GEM = "anvisa-bot"
|
|
8
|
-
GEM_VERSION = "0.2.
|
|
8
|
+
GEM_VERSION = "0.2.2"
|
|
9
9
|
SUMMARY = "Pesquisa de produtos para saúde registrados"
|
|
10
10
|
AUTHOR = "Roger Leite"
|
|
11
11
|
EMAIL = "roger.barreto@gmail.com"
|
|
@@ -18,7 +18,7 @@ spec = Gem::Specification.new do |s|
|
|
|
18
18
|
s.platform = Gem::Platform::RUBY
|
|
19
19
|
s.summary = SUMMARY
|
|
20
20
|
s.require_paths = ['bin', 'lib']
|
|
21
|
-
s.files = FileList['bin/*.rb', 'lib/**/*.rb', '[A-Z]*'
|
|
21
|
+
s.files = FileList['bin/*.rb', 'lib/**/*.rb', '[A-Z]*'].to_a
|
|
22
22
|
s.executables = ["anvisa-bot"]
|
|
23
23
|
|
|
24
24
|
s.author = AUTHOR
|
data/lib/anvisa_bot.rb
CHANGED
|
@@ -5,15 +5,19 @@ class AnvisaBot
|
|
|
5
5
|
|
|
6
6
|
#veja o fluxo de "navegacao" do bot no arquivo fluxo_site_anvisa.txt
|
|
7
7
|
def self.consulta_produto_por_registro(numero_registro)
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
begin
|
|
9
|
+
anvisa_browser = AnvisaBrowser.new
|
|
10
|
+
plain_html = anvisa_browser.consulta_produto_por_registro(numero_registro)
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
#puts "ZZZ ... ~10 segs"
|
|
13
|
+
sleep( rand(10) ) #para não chamar atencao do server
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
links = AnvisaParser.find_links_produtos(plain_html)
|
|
16
|
+
plain_html = anvisa_browser.consulta_produto_detalhe(numero_registro, links.first)
|
|
17
|
+
AnvisaParser.extract_produto(plain_html)
|
|
18
|
+
rescue => ex
|
|
19
|
+
AnvisaParser.extract_produto('', ex)
|
|
20
|
+
end
|
|
17
21
|
end
|
|
18
22
|
|
|
19
23
|
end
|
data/lib/anvisa_parser.rb
CHANGED
|
@@ -17,7 +17,13 @@ class AnvisaParser
|
|
|
17
17
|
links
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def self.extract_produto(plain_html)
|
|
20
|
+
def self.extract_produto(plain_html, exception = nil)
|
|
21
|
+
if !!exception
|
|
22
|
+
produto = Produto.new({})
|
|
23
|
+
produto.error = exception
|
|
24
|
+
return produto
|
|
25
|
+
end
|
|
26
|
+
|
|
21
27
|
html = Hpricot(plain_html)
|
|
22
28
|
|
|
23
29
|
table = html.at("table.formulario")
|
|
@@ -67,7 +73,8 @@ class Produto
|
|
|
67
73
|
|
|
68
74
|
attr_accessor :empresa, :cnpj, :autorizacao,
|
|
69
75
|
:nome, :modelo, :registro,
|
|
70
|
-
:processo,:origem, :vencimento_registro
|
|
76
|
+
:processo,:origem, :vencimento_registro,
|
|
77
|
+
:error
|
|
71
78
|
|
|
72
79
|
def initialize(args)
|
|
73
80
|
raise ArgumentError("Args have to be a Hash with attributes") unless args.is_a?(Hash)
|
|
@@ -76,5 +83,9 @@ class Produto
|
|
|
76
83
|
end
|
|
77
84
|
end
|
|
78
85
|
|
|
86
|
+
def error?
|
|
87
|
+
!!error
|
|
88
|
+
end
|
|
89
|
+
|
|
79
90
|
end
|
|
80
91
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rogerleite-anvisa-bot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Roger Leite
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-08-
|
|
12
|
+
date: 2009-08-17 00:00:00 -07:00
|
|
13
13
|
default_executable: anvisa-bot
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
@@ -32,15 +32,11 @@ extra_rdoc_files: []
|
|
|
32
32
|
|
|
33
33
|
files:
|
|
34
34
|
- lib/anvisa_bot.rb
|
|
35
|
-
- lib/anvisa_browser.rb
|
|
36
35
|
- lib/anvisa_parser.rb
|
|
37
|
-
-
|
|
36
|
+
- lib/anvisa_browser.rb
|
|
38
37
|
- Rakefile
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
- anvisa-bot.gemspec
|
|
42
|
-
- bin
|
|
43
|
-
- lib
|
|
38
|
+
- FLUXO_SITE_ANVISA.txt
|
|
39
|
+
- README.textile
|
|
44
40
|
- bin/anvisa-bot
|
|
45
41
|
has_rdoc: false
|
|
46
42
|
homepage: http://github.com/rogerleite/anvisa-bot
|
data/anvisa-bot.gemspec
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
|
|
3
|
-
Gem::Specification.new do |s|
|
|
4
|
-
s.name = %q{anvisa-bot}
|
|
5
|
-
s.version = "0.2.1"
|
|
6
|
-
|
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
8
|
-
s.authors = ["Roger Leite"]
|
|
9
|
-
s.date = %q{2009-08-10}
|
|
10
|
-
s.default_executable = %q{anvisa-bot}
|
|
11
|
-
s.email = %q{roger.barreto@gmail.com}
|
|
12
|
-
s.executables = ["anvisa-bot"]
|
|
13
|
-
s.files = ["lib/anvisa_bot.rb", "lib/anvisa_browser.rb", "lib/anvisa_parser.rb", "README.textile", "Rakefile", "spec", "fluxo_site_anvisa.txt", "anvisa-bot.gemspec", "bin", "lib", "bin/anvisa-bot"]
|
|
14
|
-
s.homepage = %q{http://github.com/rogerleite/anvisa-bot}
|
|
15
|
-
s.require_paths = ["bin", "lib"]
|
|
16
|
-
s.rubyforge_project = %q{anvisa-bot}
|
|
17
|
-
s.rubygems_version = %q{1.3.1}
|
|
18
|
-
s.summary = %q{Pesquisa de produtos para saúde registrados}
|
|
19
|
-
|
|
20
|
-
if s.respond_to? :specification_version then
|
|
21
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
22
|
-
s.specification_version = 2
|
|
23
|
-
|
|
24
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
25
|
-
s.add_runtime_dependency(%q<hpricot>, [">= 0.8.1"])
|
|
26
|
-
else
|
|
27
|
-
s.add_dependency(%q<hpricot>, [">= 0.8.1"])
|
|
28
|
-
end
|
|
29
|
-
else
|
|
30
|
-
s.add_dependency(%q<hpricot>, [">= 0.8.1"])
|
|
31
|
-
end
|
|
32
|
-
end
|