My last post wasn't actually relevant to ruby so here's a little snippet 
using ruby, sqlite and worldkit. I'm just learning ruby myself so this 
might not be the best way to do this.

require 'open-uri'
require 'sqlite3'

# make a table with two records, Dallas, TX and Lansing, MI
database = SQLite3::Database.new( "cities.database" )
database.execute( "create table city_names (id INTEGER PRIMARY KEY, name 
TEXT, state TEXT, country TEXT, latitude NUMERIC, long NUMERIC);")
database.execute( "insert into city_names (name, state, country) values 
('Dallas', 'TX', 'US')")
database.execute( "insert into city_names (name, state, country) values 
('Lansing', 'MI', 'US')")

class Geocoder
  def initialize(db)
    @db = db
    @rows = db.execute( "select * from city_names")
  end

  def update_coords
    @link = ""
    @rows.each do |item|
      @link = "#{item[1]},#{item[2]},#{item[3]}"
      open("http://brainoff.com/worldkit/geocoder/rest/?city=#{@link}") 
do |f|
         sd = f.read
        @long = sd.scan(/long>(.*)</)
        @lat = sd.scan(/lat>(.*)</)
      end
    @db.execute( "UPDATE city_names SET long ='#{@long[0][0]}' WHERE 
id=#{item[0]}")
    @db.execute( "UPDATE city_names SET latitude ='#{@lat[0][0]}' WHERE 
id=#{item[0]}")
    end
  end
end

geo = Geocoder.new(database)
geo.update_coords
-- 
Posted via http://www.ruby-forum.com/.