Skip to content

Instantly share code, notes, and snippets.

@dsalazar32
Created January 11, 2012 17:49
Show Gist options
  • Select an option

  • Save dsalazar32/1595833 to your computer and use it in GitHub Desktop.

Select an option

Save dsalazar32/1595833 to your computer and use it in GitHub Desktop.
Informatica src description
require 'rubygems'
require 'sequel'
require 'net/http'
require 'net/https'
require 'json'
KEY = 'XXX'
CONN = Sequel.connect(:adapter => 'mysql2', :host => 'localhost',
:user => 'root', :database => 'auto_informatic')
# Get GOIP
def fetch_geolocation(addr)
uri = URI('http://maps.googleapis.com/maps/api/geocode/json')
params = {:address => addr, :sensor => false}
uri.query = URI.encode_www_form(params)
res = Net::HTTP.get_response(uri)
data = JSON.parse(res.body)
"#{data['results'][0]['geometry']['location']['lat']},#{data['results'][0]['geometry']['location']['lng']}"
end
# Get place details reference id
def fetch_place_details_reference(loc, kwd)
uri = URI.parse('https://maps.googleapis.com/maps/api/place/search/json')
params = {:location => loc, :keyword => kwd, :sensor => false, :key => KEY, :radius => 10}
uri.query = URI.encode_www_form(params)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
req = Net::HTTP::Get.new(uri.request_uri)
res = http.request(req)
data = JSON.parse(res.body)
data['status'] == 'OK' ? "#{data['results'][0]['reference']}" : ""
end
# Get details phone number
def fetch_details(ref)
uri = URI.parse('https://maps.googleapis.com/maps/api/place/details/json')
params = {:reference => ref, :sensor => false, :key => KEY}
uri.query = URI.encode_www_form(params)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
req = Net::HTTP::Get.new(uri.request_uri)
res = http.request(req)
data = JSON.parse(res.body)
"#{data['result']['formatted_phone_number']}"
end
ds = CONN[:informatica].filter(:TEL => '') # Dataset
p "Total records: #{ds.count}"
ds.each do |r|
query_addr = "#{r[:CO_ADD]} #{r[:CO_CITY]} FL, #{r[:CO_ZIP]}"
geo_location = fetch_geolocation(query_addr)
reference_num = fetch_place_details_reference(geo_location, r[:CO_NAME])
tel = fetch_details(reference_num) unless reference_num.empty?
if !tel.nil?
p "# Number located record id: #{r[:id]}"
ds.filter(:id => r[:id]).update(:TEL => tel)
end
sleep 2
end
p 'Process COMPLETE'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment