def __get_uri(path): if path.startswith("/"): path = path.lstrip("/") return "%s/%s" % (safe_get_config('hackathon-api.endpoint', 'http://localhost:15000'), path)
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # ----------------------------------------------------------------------------------- from flask import Flask from flask_debugtoolbar import DebugToolbarExtension from functions import safe_get_config from database import db_session # flask app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = safe_get_config("mysql.connection", "mysql://*****:*****@localhost/hackathon") app.config['SECRET_KEY'] = safe_get_config("app.secret_key", "secret_key") app.config['DEBUG_TB_ENABLED'] = False toolbar = DebugToolbarExtension(app) @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove() class Context(object): """Helper class for JSON. We can access dict similarly as literal in JS Essentially a collection of parameters that will be passed through threads/databases
def index(): return render_template("index.html", providers=safe_get_config("login.provider_enabled", ["github", "qq", "gitcafe"]))
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # ----------------------------------------------------------------------------------- from flask import Flask from flask_debugtoolbar import DebugToolbarExtension from functions import safe_get_config # flask app = Flask(__name__) app.config['SECRET_KEY'] = safe_get_config("app.secret_key", "secret_key") app.config['DEBUG_TB_ENABLED'] = False toolbar = DebugToolbarExtension(app) class Context(object): """Helper class for JSON. We can access dict similarly as literal in JS Essentially a collection of parameters that will be passed through threads/databases NEVER put complex object in Context such as instance of db models or business manager ::Example: dic = {"a": "va", "b": {"b1": "b1", "b2": [1, 2, 3], "b3": [{"b3a": "b3a"}]}} c = Context.from_object(dic) # convert existing obj to Context
from . import app import os from log import log def scheduler_listener(event): if event.code == EVENT_JOB_ERROR: print('The job crashed :(') log.warn("The schedule job crashed because of %s" % repr(event.exception)) else: print('The job executed :)') log.debug("The schedule job %s executed and return value is '%s'" % (event.job_id, event.retval)) if not app.debug or os.environ.get('WERKZEUG_RUN_MAIN') == 'true': scheduler = BackgroundScheduler() # job store if safe_get_config("scheduler.job_store", "memory") == "mysql": scheduler.add_jobstore('sqlalchemy', url=get_config("scheduler.job_store_url")) # listener # do we need listen EVENT_JOB_MISSED? scheduler.add_listener(scheduler_listener, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR) scheduler.start()
# -*- coding: utf-8 -*- """ This file is covered by the LICENSING file in the root of this project. """ from flask import Flask from flask_debugtoolbar import DebugToolbarExtension from functions import safe_get_config # flask app = Flask(__name__) app.config['SECRET_KEY'] = safe_get_config("app.secret_key", "secret_key") app.config['DEBUG_TB_ENABLED'] = False toolbar = DebugToolbarExtension(app) class Context(object): """Helper class for JSON. We can access dict similarly as literal in JS Essentially a collection of parameters that will be passed through threads/databases NEVER put complex object in Context such as instance of db models or business manager ::Example: dic = {"a": "va", "b": {"b1": "b1", "b2": [1, 2, 3], "b3": [{"b3a": "b3a"}]}} c = Context.from_object(dic) # convert existing obj to Context print c.a print c["a"] # exactly the same as c.a. But it allows you pass values to key
def index(): return render_template("index.html", providers=safe_get_config("login.provider_enabled", ["github", "qq", "gitcafe", "weibo"]), meta_content=oauth_meta_content() )
from functions import safe_get_config, get_config from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.events import EVENT_JOB_EXECUTED, EVENT_JOB_ERROR from . import app import os from log import log def scheduler_listener(event): if event.code == EVENT_JOB_ERROR: print('The job crashed :(') log.warn("The schedule job crashed because of %s" % repr(event.exception)) else: print('The job executed :)') log.debug("The schedule job %s executed and return value is '%s'" % (event.job_id, event.retval)) if not app.debug or os.environ.get('WERKZEUG_RUN_MAIN') == 'true': scheduler = BackgroundScheduler() # job store if safe_get_config("scheduler.job_store", "memory") == "mysql": scheduler.add_jobstore('sqlalchemy', url=get_config("scheduler.job_store_url")) # listener # do we need listen EVENT_JOB_MISSED? scheduler.add_listener(scheduler_listener, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR) scheduler.start()
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # ----------------------------------------------------------------------------------- from flask import Flask from functions import safe_get_config from flask_debugtoolbar import DebugToolbarExtension # flask app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = safe_get_config( "mysql.connection", "mysql://*****:*****@localhost/hackathon") app.config['SECRET_KEY'] = safe_get_config("app.secret_key", "secret_key") app.config['DEBUG_TB_ENABLED'] = False toolbar = DebugToolbarExtension(app) class Context(object): """Helper class for JSON. We can access dict similarly as literal in JS Essentially a collection of parameters that will be passed through threads/databases NEVER put complex object in Context such as instance of db models or business manager ::Example: dic = {"a": "va", "b": {"b1": "b1", "b2": [1, 2, 3], "b3": [{"b3a": "b3a"}]}} c = Context.from_object(dic) # convert existing obj to Context