Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- import sys
- import shutil
- import math
- import sqlite3
- import bottle
- class EnableCors(object):
- name = 'enable_cors'
- api = 2
- def apply(self, fn, context):
- def _enable_cors(*args, **kwargs):
- bottle.response.headers['Access-Control-Allow-Origin'] = '*'
- bottle.response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'
- bottle.response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
- if bottle.request.method != 'OPTIONS':
- return fn(*args, **kwargs)
- return _enable_cors
- app = bottle.app()
- app.install(EnableCors())
- db = sqlite3.connect( sys.argv[1] )
- def get_tile(z,x,y):
- z = int(z)
- x = int(x)
- y = int(y)
- print (z,x,y)
- q = "SELECT tile_data FROM tiles WHERE zoom_level=%d AND tile_column=%d AND tile_row=%d" % (z, x, y)
- cur = db.cursor()
- cur.execute( q )
- data = cur.fetchone()
- return bytes(data)
- @app.get('/<z>/<x>/<y>', methods=['GET'])
- def tiles(z=0, x=0, y=0):
- bottle.response.content_type = 'application/x-protobuf'
- # bottle.response.content_encoding = 'gzip'
- tile = get_tile(z, x, y)
- return tile
- # http://localhost:8080/12/2198/2752
- bottle.run( host='localhost', port=8080, debug=True, reloader=True )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement