diff --git a/app-engine/main.py b/app-engine/main.py index fa98f67..5b5c860 100644 --- a/app-engine/main.py +++ b/app-engine/main.py @@ -2,8 +2,10 @@ # Imports # from os.path import dirname, join +import arrow +import dateutil -from flask import Flask, render_template +from flask import Flask, render_template, jsonify # @@ -27,6 +29,35 @@ def main_index(): """Home page.""" return render_template('index.html') +# Arrow API +# Mainly to test fix for this issue: +# +@app.route('/arrow/version') +def arrow_version(): + return jsonify({ + 'arrow': arrow.VERSION, + 'dateutil': dateutil.__version__ + }) + +@app.route('/arrow/now') +@app.route('/arrow/now/') +def arrow_now(timezone=None): + now = arrow.utcnow() + json_data = { + 'now': str(now), + 'timezone': 'UTC' + } + + if timezone: + timezone = timezone.replace('-', '/') + json_data['timezone'] = timezone + try: + json_data['now'] = str(now.to(timezone)) + except arrow.parser.ParserError, e: + json_data['now'] = None + json_data['error'] = str(e) + + return jsonify(json_data) # # Exception Handlers diff --git a/app-engine/requirements.txt b/app-engine/requirements.txt index a257e29..efe7017 100644 --- a/app-engine/requirements.txt +++ b/app-engine/requirements.txt @@ -5,3 +5,9 @@ # # Note: The `lib` directory is added to `sys.path` by `appengine_config.py`. Flask==0.10 + +# Arrow requires dateutil and dateutil > 1.5 requires subprocess module which App Engine +# does not allow. So we peg dateutil here to 1.5. +# See https://github.com/crsmithdev/arrow/issues/240 +arrow +python-dateutil==1.5