def com_config_read(db_prod=True): """ Read in the database connection and open unless specified not too """ # open the database db_connection = database_base.ServerDatabase() db_connection.db_open() return db_connection
from flask import Flask, request, g, Response, jsonify from flask.ext.restful import Api, Resource from werkzeug.exceptions import NotFound, UnsupportedMediaType import json import database # Media type constants: # http://amundsen.com/media-types/collection/ COLLECTIONJSON = "application/vnd.collection+json" # Define the application: app = Flask(__name__) app.debug = True app.config['DATABASE'] = database.ServerDatabase(database.DEFAULT_DB_PATH) # Define the api: api = Api(app) def createErrorResponse(status_code, title, message, resource_type=None): '''Creates a json error response.''' response = jsonify(title=title, message=message, resource_type=resource_type) response.status_code = status_code return response @app.before_request def set_database(): '''Stores an instance of the database API before each request in flask.g variable accessible only from the app context'''
def before_request(): """ Executes before each request """ g.db_connection = database_base.ServerDatabase() g.db_connection.db_open()
modify it under the terms of the GNU General Public License version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more details. You should have received a copy of the GNU General Public License version 2 along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ''' import calculations as calculations_base import database as database_base # open up the database db_connection = database_base.ServerDatabase() db_connection.db_open() calc_inst = calculations_base.Calculations(db_connection) db_connection.db_wealth_poe_ninja_currency_write( calc_inst.com_wealth_ninja_fetch_api()) # commit db_connection.db_commit() # close the database db_connection.db_close()
logger.addHandler(cl_handler) logger.addHandler(f_handler) logger.setLevel(level) if __name__ == '__main__': # intialize everything client = discord.Client() config = get_config() setup_logging(config) logger = logging.getLogger() db = database.ServerDatabase(config["dbuser"], config["dbname"], config["dbhost"], logger, config["dbpass"]) bot = Hasami(client, logger, config, db) message_processor = MessageProcessor(client, bot, config["prefix"], logger, db) # client events @client.event async def on_ready(): logger.info("logged in as {0}".format(client.user.name)) await bot.start() @client.event async def on_message(message): await message_processor.process_message(message)