source: subversion/applications/utils/mod_tile/mysql2file.rb @ 29283

Last change on this file since 29283 was 4955, checked in by jonb, 12 years ago

mod_tile: Apache module and rendering daemon for serving OSM tiles

  • Property svn:executable set to *
File size: 735 bytes
Line 
1#!/usr/bin/ruby
2require 'mysql'
3require 'date'
4require 'time'
5require 'fileutils'
6
7dbh = nil
8dbh = Mysql.real_connect('localhost', 'tile', 'tile', 'tile')
9dbh.query_with_result = false
10dbh.query("select x,y,z,data,created_at from tiles" )
11res = dbh.use_result
12
13while row = res.fetch_hash do
14    x = row['x']
15    y = row['y']
16    z = row['z']
17    created_at = Time.parse(row['created_at'])
18
19    path = "/var/www/html/osm_tiles2/#{z}/#{x}"
20    FileUtils.mkdir_p(path)
21
22    print "x(#{x}) y(#{y}) z(#{z}), created_at(#{created_at.to_i})\n"
23
24    f = File.new("#{path}/#{y}.png", "w")
25    f.print row['data']
26    f.close
27    File.utime(created_at,created_at,"#{path}/#{y}.png")
28end
29puts "Number of rows returned: #{res.num_rows}"
30
31res.free
Note: See TracBrowser for help on using the repository browser.