File: tile.py

package info (click to toggle)
thuban 1.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 7,596 kB
  • ctags: 5,301
  • sloc: python: 30,411; ansic: 6,181; xml: 4,127; cpp: 1,595; makefile: 166; sh: 101
file content (32 lines) | stat: -rwxr-xr-x 734 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
import cgi
import cgitb
cgitb.enable()
import cStringIO

PATH_TO_TILES = "/path/to/tiles"

size = 256 #image width and height

def getTile(x, y, z):
    z = int(z)
    y = int(y)
    x = int(x)
    
    try:
        f = open('%s/%d/%d.%d.png' % (PATH_TO_TILES, z, x, y))
    except IOError:
        print "Content-type: text/plain\n\nNothing"
        return

    print "Content-type: image/png\n"
    print f.read()

if __name__ == "__main__":
    form = cgi.FieldStorage()
    if "x" in form and "y" in form and "z" in form:
        getTile(form["x"].value, form["y"].value, form["z"].value)
    else:
        print "Content-type: text/html\n"
        print """<html><body>Missing input arguments</body></html>"""