raktojson 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/raktojson/cli.rb +10 -9
- data/lib/raktojson/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05d056f064846cf4fd6f281abddfb2c176cd57ac
|
4
|
+
data.tar.gz: 9451d74308bc6726fbc496215dd58d9e468fe08a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d56532586e0561dfabf25ac85e755c02c28ad75816c38bc7cf8bf89d9b1302de3f9f430be923b85b2f08860199a89af8b7fb64965d922b093084bfb2a01c0fa6
|
7
|
+
data.tar.gz: 29de6084b37ae872d6e6ef9abf511c9fa450860a38284f056c927fe0a16a9b7357232a8e9fca58417b48a5c6046d76ce2af8a1f44e46bfbdfb06b1abf0d713f7
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# :pizza: RAKToJSON
|
2
|
+
[](https://github.com/maxmouchet/raktojson/blob/master/LICENSE.txt)
|
3
|
+
[](https://rubygems.org/gems/raktojson)
|
4
|
+
[](https://travis-ci.org/maxmouchet/raktojson)
|
2
5
|
|
3
6
|
Parser for Télécom Bretagne restaurant menus.
|
4
7
|
|
data/lib/raktojson/cli.rb
CHANGED
@@ -19,13 +19,6 @@ module RAKToJSON
|
|
19
19
|
|
20
20
|
end.parse(argv)
|
21
21
|
|
22
|
-
def download_pdf(link, &block)
|
23
|
-
destination = "/tmp/#{ SecureRandom.hex(16) }.pdf"
|
24
|
-
`curl -o #{ destination } #{ link } 2&>/dev/null`
|
25
|
-
block.call(destination)
|
26
|
-
File.delete(destination)
|
27
|
-
end
|
28
|
-
|
29
22
|
options[:url] ||= 'http://services.telecom-bretagne.eu/rak/fr/menus_restaurant/'
|
30
23
|
|
31
24
|
if options[:url].end_with?('.pdf')
|
@@ -33,17 +26,25 @@ module RAKToJSON
|
|
33
26
|
links = [ options[:url] ]
|
34
27
|
else
|
35
28
|
$stderr.puts "Downloading menus from #{ options[:url] }"
|
36
|
-
links = WeekListParser.parse(options[:url])
|
29
|
+
links = WeekListParser.parse(open(options[:url]))
|
37
30
|
end
|
38
31
|
|
39
32
|
$stderr.puts "#{ links.count } menus to parse"
|
40
33
|
links.each do |link|
|
41
|
-
download_pdf(link) do |pdf|
|
34
|
+
self.download_pdf(link) do |pdf|
|
42
35
|
xml_menu = `pdftohtml -xml -stdout -enc UTF-8 #{ pdf }`
|
43
36
|
puts XMLMenuParser.parse(xml_menu)
|
44
37
|
end
|
45
38
|
end
|
46
39
|
end
|
47
40
|
|
41
|
+
private
|
42
|
+
def self.download_pdf(link, &block)
|
43
|
+
destination = "/tmp/#{ SecureRandom.hex(16) }.pdf"
|
44
|
+
`curl -o #{ destination } #{ link } 2&>/dev/null`
|
45
|
+
block.call(destination)
|
46
|
+
File.delete(destination)
|
47
|
+
end
|
48
|
+
|
48
49
|
end
|
49
50
|
end
|
data/lib/raktojson/version.rb
CHANGED