source: src/django_gheat/wlheatmap/osm_proxy.py@ 9396

Last change on this file since 9396 was 9391, checked in by rick, 14 years ago

Get some hints on when cache is used and when we are fetching data actually. To check if we do not exeeed the bandwidth limitations.

File size: 692 bytes
Line 
1#
2# Hack to cache OSM tile images locally, using file based django caching
3#
4# Rick van der Zwet <info@rickvanderzwet.nl>
5#
6from django.views.decorators.cache import cache_page
7from django.http import HttpResponse
8
9import settings
10import random
11import urllib
12
13import logging
14logger = logging.getLogger(__name__)
15
16
17# Create your views here.
18@cache_page(60 * 60 * 24 * 7)
19def osm_proxy(request,zoom,x,y):
20 mirror = random.choice(['a','b','c'])
21 url = 'http://%s.tile.openstreetmap.org/%s/%s/%s.png' % (mirror, zoom, x, y)
22 logger.info("Fetching tile from %s" % url)
23 data = urllib.urlopen(url).read()
24 response = HttpResponse(mimetype="image/png")
25 response.write(data)
26 return response
Note: See TracBrowser for help on using the repository browser.