2018-10-03 17:37:45 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# vim: set encoding=utf-8
|
|
|
|
|
2018-10-07 10:11:09 +00:00
|
|
|
from gevent.pywsgi import WSGIServer
|
|
|
|
from gevent.monkey import patch_all
|
|
|
|
patch_all()
|
|
|
|
|
|
|
|
# pylint: disable=wrong-import-position,wrong-import-order
|
2018-10-03 17:37:45 +00:00
|
|
|
import sys
|
2015-12-26 22:22:13 +00:00
|
|
|
import os
|
2018-10-07 10:11:09 +00:00
|
|
|
import jinja2
|
|
|
|
|
|
|
|
from flask import Flask, request, send_from_directory
|
|
|
|
APP = Flask(__name__)
|
|
|
|
|
2018-10-03 20:59:11 +00:00
|
|
|
MYDIR = os.path.abspath(
|
|
|
|
os.path.dirname(os.path.dirname('__file__')))
|
2018-10-03 17:37:45 +00:00
|
|
|
sys.path.append("%s/lib/" % MYDIR)
|
2018-10-07 10:11:09 +00:00
|
|
|
|
|
|
|
import wttr_srv
|
|
|
|
from globals import TEMPLATES, STATIC, LISTEN_HOST, LISTEN_PORT
|
|
|
|
# pylint: enable=wrong-import-position,wrong-import-order
|
|
|
|
|
|
|
|
|
|
|
|
MY_LOADER = jinja2.ChoiceLoader([
|
|
|
|
APP.jinja_loader,
|
|
|
|
jinja2.FileSystemLoader(TEMPLATES),
|
|
|
|
])
|
|
|
|
APP.jinja_loader = MY_LOADER
|
|
|
|
|
|
|
|
@APP.route('/files/<path:path>')
|
|
|
|
def send_static(path):
|
|
|
|
"Send any static file located in /files/"
|
|
|
|
return send_from_directory(STATIC, path)
|
|
|
|
|
|
|
|
@APP.route('/favicon.ico')
|
|
|
|
def send_favicon():
|
|
|
|
"Send static file favicon.ico"
|
|
|
|
return send_from_directory(STATIC, 'favicon.ico')
|
|
|
|
|
|
|
|
@APP.route('/malformed-response.html')
|
|
|
|
def send_malformed():
|
|
|
|
"Send static file malformed-response.html"
|
|
|
|
return send_from_directory(STATIC, 'malformed-response.html')
|
|
|
|
|
|
|
|
@APP.route("/")
|
|
|
|
@APP.route("/<string:location>")
|
|
|
|
def wttr(location=None):
|
|
|
|
"Main function wrapper"
|
|
|
|
return wttr_srv.wttr(location, request)
|
|
|
|
|
|
|
|
SERVER = WSGIServer((LISTEN_HOST, LISTEN_PORT), APP)
|
|
|
|
SERVER.serve_forever()
|