コード例 #1
0
ファイル: api.py プロジェクト: juanborbon93/fast_pony_crud
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)
コード例 #2
0
ファイル: account.py プロジェクト: hayate-hsu/bidong_backend
def bind(weixin, user):
    '''
        weixin : weixin bd_account
        user : holder's id
    '''
    db.bind(weixin, user)
コード例 #3
0
ファイル: flask_app.py プロジェクト: jianjian01/homepage
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(
コード例 #4
0
ファイル: main.py プロジェクト: Rurson/fastapi_playground
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)
コード例 #5
0
            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()
コード例 #6
0
ファイル: main.py プロジェクト: benquick123/nfc_work_backend
                    '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()