Created
December 17, 2014 17:23
-
-
Save bahamut45/5e9231df620dc559a3b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open-uri' | |
require 'json' | |
require 'uri' | |
# colors | |
BOLD = "\e[1;39m" | |
RESET = "\e[0m" | |
def main | |
search = ARGV[0] or exit | |
url = "https://rtgi.giprecia.fr/ajax/autocomplete-rne.html?text=#{search}" | |
json = open URI.escape url | |
data = JSON.load json | |
if (!data.any?) then abort("Etablissement inexistant") end | |
data.each do |x| | |
value = x.values.join | |
if /^(?<rne>\d+[a-z]) - (?<desc>.*)$/ =~ value | |
puts "#{BOLD}#{rne}#{RESET} #{desc}" | |
end | |
end | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version corrigé :