rogerleite-anvisa-bot 0.2.2 → 0.2.3
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/Rakefile +1 -1
- data/lib/anvisa_bot.rb +10 -3
- data/lib/anvisa_parser.rb +6 -7
- metadata +2 -2
data/Rakefile
CHANGED
data/lib/anvisa_bot.rb
CHANGED
|
@@ -6,19 +6,26 @@ class AnvisaBot
|
|
|
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
8
|
begin
|
|
9
|
-
anvisa_browser =
|
|
9
|
+
anvisa_browser = create_anvisa_browser
|
|
10
10
|
plain_html = anvisa_browser.consulta_produto_por_registro(numero_registro)
|
|
11
11
|
|
|
12
12
|
#puts "ZZZ ... ~10 segs"
|
|
13
|
-
sleep( rand(10) ) #para não chamar atencao do server
|
|
13
|
+
#sleep( rand(10) ) #para não chamar atencao do server
|
|
14
14
|
|
|
15
15
|
links = AnvisaParser.find_links_produtos(plain_html)
|
|
16
|
+
return Produto.new({:not_found => true}) if links.empty?
|
|
17
|
+
|
|
16
18
|
plain_html = anvisa_browser.consulta_produto_detalhe(numero_registro, links.first)
|
|
17
19
|
AnvisaParser.extract_produto(plain_html)
|
|
18
20
|
rescue => ex
|
|
19
|
-
|
|
21
|
+
Produto.new({:error => ex})
|
|
20
22
|
end
|
|
21
23
|
end
|
|
22
24
|
|
|
25
|
+
#usado para injetar stubs ao rodar specs
|
|
26
|
+
def self.create_anvisa_browser
|
|
27
|
+
AnvisaBrowser.new
|
|
28
|
+
end
|
|
29
|
+
|
|
23
30
|
end
|
|
24
31
|
|
data/lib/anvisa_parser.rb
CHANGED
|
@@ -17,12 +17,7 @@ class AnvisaParser
|
|
|
17
17
|
links
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def self.extract_produto(plain_html
|
|
21
|
-
if !!exception
|
|
22
|
-
produto = Produto.new({})
|
|
23
|
-
produto.error = exception
|
|
24
|
-
return produto
|
|
25
|
-
end
|
|
20
|
+
def self.extract_produto(plain_html)
|
|
26
21
|
|
|
27
22
|
html = Hpricot(plain_html)
|
|
28
23
|
|
|
@@ -74,7 +69,7 @@ class Produto
|
|
|
74
69
|
attr_accessor :empresa, :cnpj, :autorizacao,
|
|
75
70
|
:nome, :modelo, :registro,
|
|
76
71
|
:processo,:origem, :vencimento_registro,
|
|
77
|
-
:error
|
|
72
|
+
:error, :not_found
|
|
78
73
|
|
|
79
74
|
def initialize(args)
|
|
80
75
|
raise ArgumentError("Args have to be a Hash with attributes") unless args.is_a?(Hash)
|
|
@@ -87,5 +82,9 @@ class Produto
|
|
|
87
82
|
!!error
|
|
88
83
|
end
|
|
89
84
|
|
|
85
|
+
def not_found?
|
|
86
|
+
!!not_found
|
|
87
|
+
end
|
|
88
|
+
|
|
90
89
|
end
|
|
91
90
|
|
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.3
|
|
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-19 00:00:00 -07:00
|
|
13
13
|
default_executable: anvisa-bot
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|