from fastapi import FastAPI from db import db from fast_pony_crud import create_crud_routes import uvicorn import os app = FastAPI() database_url = os.environ.get('DATABASE_URL') if database_url: db.bind(provider='postgres', dsn=database_url) else: db.bind(provider='sqlite', filename='database.sqlite', create_db=True) db.generate_mapping(create_tables=True) create_crud_routes(db,app,api_key="test") if __name__ == "__main__": uvicorn.run(app)
def bind(weixin, user): ''' weixin : weixin bd_account user : holder's id ''' db.bind(weixin, user)
from flask_redis import FlaskRedis from flask_wtf import CSRFProtect from pony.flask import Pony from config import Config from db import db as mysql # flask flask_app = Flask(__name__) flask_app.config.from_object(Config) flask_app.jinja_env.add_extension('jinja2.ext.i18n') CSRFProtect(flask_app) # mysql mysql.bind(**flask_app.config['PONY']) mysql.generate_mapping() pony = Pony(flask_app) # redis redis = FlaskRedis(flask_app) babel = Babel(flask_app) @babel.localeselector def get_locale(): locale = request.cookies.get('locale', '') if locale: return locale return request.accept_languages.best_match(
my_list = ["Hello", "World"] api = FastAPI() templates = Jinja2Templates(directory="templates") api.mount("/static", StaticFiles(directory="static"), name="static") provider = os.getenv("DATABASE_PROVIDER", "postgres") user = os.getenv("DATABASE_USER", "postgres") password = os.getenv("DATABASE_PASSWORD", "pass") host = os.getenv("DATABASE_HOST", "localhost") database = os.getenv("DATABASE_DATABASE", "fastapi") db.bind( provider=provider, user=user, password=password, host=host, database=database, ) db.generate_mapping(create_tables=True) user_repo = UserRepository() @dataclass class User_Entity: name: str password: str id: int = None db_d = defaultdict(list)
ts = time.time() content_len = int(self.headers.get('Content-Length')) data = json.loads(self.rfile.read(content_len)) with db_session: Event(event=event, repo=data['repository']['full_name'], branch=data['ref']) self._set_response() self.wfile.write(bytes("ok", "utf-8")) def run_http_server(server_class=HTTPServer, handler_class=S, port=settings['http_server_port']): logging.basicConfig(level=logging.INFO) server_address = ('', port) httpd = server_class(server_address, handler_class) logging.info('Starting httpd...\n') try: httpd.serve_forever() except KeyboardInterrupt: pass httpd.server_close() logging.info('Stopping httpd...\n') if __name__ == '__main__': db.bind(**settings['db']) db.generate_mapping(create_tables=True) run_http_server()
'response': "404, but not really", 'message': "format " + str(query_dict['format']) + " not supported" }) else: return json.dumps({'response': 'SEARCH EXECUTED.', 'data': result}) def DELETE(self): web.header('Content-Type', 'application/json') return json.dumps({'response': "NOT IMPLEMENTED."}) if __name__ == '__main__': db.bind(provider='mysql', host='localhost', user='******', passwd='AQqBRMqQ&D8?wZNA', db='navig01_nfcwork') db.generate_mapping(create_tables=True) app = web.application(urls, globals()) app.run() else: # uncomment this when deploying! db.bind(provider='mysql', host='localhost', user='******', passwd='AQqBRMqQ&D8?wZNA', db='navig01_nfcwork') db.generate_mapping(create_tables=True) application = web.application(urls, globals()).wsgifunc()