Permalink
Browse files

add hsb import script

amend geokit url for specify hongkong locations
also use yahoo map api
minor updates of geo helper to make hangseng bank work
  • Loading branch information...
1 parent 34e685d commit c0b9ac841f8e84874c91baa06223e646fec306d5 @siuying committed Sep 27, 2009
@@ -17,9 +17,9 @@ def point_to_poi(point, ref_point)
:lon => (point.lng * 1000000).to_i,
:title => point.name,
:line2 => point.address,
- :line3 => point.phone,
+ :line3 => point.phone || "",
:line4 => "",
- :type => 0
+ :type => point.point_type
}
end
end
@@ -7,7 +7,7 @@
# This is the timeout value in seconds to be used for calls to the geocoder web
# services. For no timeout at all, comment out the setting. The timeout unit
# is in seconds.
- Geokit::Geocoders::timeout = 3
+ Geokit::Geocoders::timeout = 5
# These settings are used if web service calls must be routed through a proxy.
# These setting can be nil if not needed, otherwise, addr and port must be
@@ -21,7 +21,7 @@
# This is your yahoo application key for the Yahoo Geocoder.
# See http://developer.yahoo.com/faq/index.html#appid
# and http://developer.yahoo.com/maps/rest/V1/geocode.html
- # Geokit::Geocoders::yahoo = 'REPLACE_WITH_YOUR_YAHOO_KEY'
+ Geokit::Geocoders::yahoo = ENV['YMAP_KEY']
# This is your Google Maps geocoder key.
# See http://www.google.com/apis/maps/signup.html
@@ -52,7 +52,7 @@
# Be aware that there are Terms of Use restrictions on how you can use the
# various geocoders. Make sure you read up on relevant Terms of Use for each
# geocoder you are going to use.
- Geokit::Geocoders::provider_order = [:google,:us]
+ Geokit::Geocoders::provider_order = [:google,:yahoo]
# The IP provider order. Valid symbols are :ip,:geo_plugin.
# As before, make sure you read up on relevant Terms of Use for each
View
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090911151640) do
+ActiveRecord::Schema.define(:version => 20090927173634) do
create_table "points", :force => true do |t|
t.string "group"
@@ -21,6 +21,7 @@
t.decimal "lng"
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "point_type", :default => "0"
end
add_index "points", ["group"], :name => "index_points_on_group"
View
@@ -0,0 +1,33 @@
+require 'rubygems'
+require 'open-uri'
+require 'hpricot'
+
+BASE = "http://www.hangseng.com/hsb/chi/abo/cu/ba/index.html"
+XPATH_BRANCH = "//table[@bgcolor='#DDDBF9']//table//tr"
+XPATH_MTR = "//table[@bgcolor='#FFF0DB']//table//tr"
+XPATH_ATM = "//table[@bgcolor='#DAF4DC']//table//tr"
+
+html = open(BASE).read
+doc = Hpricot(html)
+
+def parse(doc, xpath, type)
+ (doc/xpath).collect do |row|
+ cols = (row/"/td")
+ name = cols[0].inner_text.tr("\n\t\r ", "") rescue nil
+ addr = cols[1].inner_text.tr("\n\t\r ", "") rescue nil
+ {:name => name, :address => addr, :type => type}
+ end.reject() {|v| v[:name].nil? || v[:address].nil? || v[:name] == "" }
+end
+
+branch = parse(doc, XPATH_BRANCH, "branch")
+branch.each do |p|
+ Point.create(:group => "hsb", :name => p[:name], :address => p[:address], :point_type => "0")
+end
+puts "branch cnt: #{branch.size}"
+
+atm = parse(doc, XPATH_ATM, "atm")
+atm.each do |p|
+ Point.create(:group => "hsb", :name => p[:name], :address => p[:address], :point_type => "1")
+end
+
+puts "atm cnt: #{atm.size}"
@@ -387,11 +387,11 @@ def self.do_geocode(address, options = {})
class GoogleGeocoder < Geocoder
private
-
+ #http://maps.google.com.hk/maps?f=q&source=s_q&hl=zh-TW&geocode=&q=hongkong&sll=22.625108,120.308954&sspn=0.410068,0.718918&ie=UTF8&ll=22.359601,114.12735&spn=0.410856,0.718918&t=h&z=11
# Template method which does the reverse-geocode lookup.
def self.do_reverse_geocode(latlng)
latlng=LatLng.normalize(latlng)
- res = self.call_geocoder_service("http://maps.google.com/maps/geo?ll=#{Geokit::Inflector::url_escape(latlng.ll)}&output=xml&key=#{Geokit::Geocoders::google}&oe=utf-8&g=hk")
+ res = self.call_geocoder_service("http://maps.google.com/maps/geo?ll=#{Geokit::Inflector::url_escape(latlng.ll)}&output=xml&key=#{Geokit::Geocoders::google}&oe=utf-8&g=hk&ll=22.625108,120.308954&spn=0.410068,0.718918")
# res = Net::HTTP.get_response(URI.parse("http://maps.google.com/maps/geo?ll=#{Geokit::Inflector::url_escape(address_str)}&output=xml&key=#{Geokit::Geocoders::google}&oe=utf-8"))
return GeoLoc.new unless (res.is_a?(Net::HTTPSuccess) || res.is_a?(Net::HTTPOK))
xml = res.body

0 comments on commit c0b9ac8

Please sign in to comment.