From 9de421175b323cc1cd71cfc59c6dcb832894f79b Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 24 Apr 2012 13:43:33 -0400 Subject: [PATCH] simple app --- Procfile | 1 + app.py | 38 ++++++++++++++++++++++++++++++++++++++ requirements.txt | 7 +++++++ 3 files changed, 46 insertions(+) create mode 100644 Procfile create mode 100644 app.py create mode 100644 requirements.txt diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..8001d1a --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn app:app \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..dab6abd --- /dev/null +++ b/app.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# -*- coding: utf-8 -*- + +""" +Python-Guide Installer +~~~~~~~~~~~~~~~~~~~~~~ + +This module provides the core redirector experience. + +Doesn't really get much simpler than this. + +""" + +import httpagentparser + +from werkzeug.wsgi import responder +from werkzeug.utils import redirect + + +LOCATIONS = { + 'linux': 'http://docs.python-guide.org/en/latest/starting/install/linux/', + 'windows': 'http://docs.python-guide.org/en/latest/starting/install/win/', + 'macintosh': 'http://docs.python-guide.org/en/latest/starting/install/osx/', + 'default': 'http://docs.python-guide.org/en/latest/index.html' +} + +@responder +def app(request, *args): + agent = httpagentparser.detect(request['HTTP_USER_AGENT'])['os']['name'].lower() + url = LOCATIONS.get(agent, LOCATIONS.get('default')) + + return redirect(url) + +if __name__ == '__main__': + from werkzeug.serving import run_simple + run_simple('localhost', 4000, app) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f5f183e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +Flask==0.8 +Jinja2==2.6 +Werkzeug==0.8.3 +distribute==0.6.24 +gunicorn==0.14.2 +httpagentparser==1.0.5 +wsgiref==0.1.2