Skip to content

Instantly share code, notes, and snippets.

@bahamut45
Created December 17, 2014 17:23
Show Gist options
  • Save bahamut45/5e9231df620dc559a3b8 to your computer and use it in GitHub Desktop.
Save bahamut45/5e9231df620dc559a3b8 to your computer and use it in GitHub Desktop.
@bahamut45
Copy link
Author

Version corrigé :

#!/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://rtgi2.giprecia.fr/ajax/autocomplete-rne.html?query=#{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