source: subversion/tile.openstreetmap.org/cat_tile.rb @ 2176

Last change on this file since 2176 was 2029, checked in by steve, 14 years ago

add hack tile stuff

  • Property svn:executable set to *
File size: 1.2 KB
Line 
1require 'cgi'
2
3cgi = CGI.new
4
5module Foo
6  require 'mysql'
7  require 'date'
8  require 'time'
9  require 'singleton'
10
11  class Bar
12    def get_local_connection
13      begin
14        return Mysql.real_connect('localhost', 'tile', 'tile', 'tile')
15      rescue MysqlError => e
16        mysql_error(e)
17      end
18    end
19
20
21    def call_local_sql
22      dbh = nil
23      begin
24        dbh = get_local_connection
25        sql = yield
26        res = dbh.query(sql)
27return res #        if res.nil? then return true else return res end
28      rescue MysqlError =>ex
29        puts ex
30      ensure
31        dbh.close unless dbh.nil?
32      end
33      nil
34    end
35  end
36end
37x = cgi['x']
38y = cgi['y']
39z = cgi['z']
40
41if z and (z.to_i > 18 or z.to_i < 2)
42  exit
43end
44
45fb = Foo::Bar.new
46
47res = fb.call_local_sql { "select data, dirty, created_at from tiles where x = #{x} and y=#{y} and z=#{z} limit 1" }
48
49if res.num_rows == 0
50  fb.call_local_sql { "insert into tiles (x,y,z,dirty, created_at) values (#{x},#{y},#{z},1,NOW())" }
51else
52  res.each_hash do |row|
53    puts row['data']
54    if row['dirty'] == '0' and Time.parse(row['created_at']) < (Time.now - (60*60*24*7))
55      fb.call_local_sql { "update tiles set dirty = 1 where x = #{x} and y=#{y} and z=#{z}" }
56    end
57  end
58end
59
Note: See TracBrowser for help on using the repository browser.