-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use aiohttp instead of wsgi and flask
- Loading branch information
1 parent
2f5d9b3
commit 1522df8
Showing
7 changed files
with
79 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
uwsgi | ||
flask | ||
aiohttp | ||
aiofiles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from main import Cache, Tile, StravaFetcher, cache_dir, auth_data | ||
from aiohttp import web | ||
|
||
cache = Cache(cache_dir) | ||
fetcher = StravaFetcher(auth_data, cache) | ||
routes = web.RouteTableDef() | ||
|
||
|
||
@routes.get(r'/{z:\d+}/{x:\d+}/{y:\d+}.png') | ||
async def get_tile(request: web.Request) -> web.StreamResponse: | ||
z = int(request.match_info['z']) | ||
x = int(request.match_info['x']) | ||
y = int(request.match_info['y']) | ||
|
||
if z < 7 or z > 16: | ||
return web.Response(status=404, reason='Zoom is out of range') | ||
|
||
tile = Tile(x, y, z) | ||
if not cache.tile_already_in_cache(tile): | ||
return web.Response(status=404, reason='Not in cache') | ||
|
||
return web.FileResponse(path=cache.abs_tile_path(tile)) | ||
|
||
|
||
if __name__ == '__main__': | ||
app = web.Application() | ||
app.add_routes(routes) | ||
web.run_app(app, port=8080) |