This repository has been archived on 2023-10-01. You can view files and clone it, but cannot push or open issues or pull requests.
PyNyaaTa/app.py

42 lines
1.2 KiB
Python
Raw Normal View History

2019-11-25 21:52:22 +00:00
from os import environ
2019-11-28 21:20:22 +00:00
from sys import modules
2019-11-25 21:52:22 +00:00
2019-11-28 21:20:22 +00:00
import pymysql
from flask import Flask
from flask_httpauth import HTTPBasicAuth
from flask_sqlalchemy import SQLAlchemy
2019-11-25 21:52:22 +00:00
2019-11-28 21:20:22 +00:00
modules["MySQLdb"] = pymysql
2019-11-25 21:52:22 +00:00
2019-11-28 21:20:22 +00:00
# init DB and migration
db_user = environ.get('MYSQL_USER')
db_password = environ.get('MYSQL_PASSWORD')
db_name = environ.get('MYSQL_DATABASE')
db_host = environ.get('MYSQL_HOST')
if not db_host or not db_user or not db_password or not db_name:
print('Missing connection environment variables')
exit()
2019-11-25 21:52:22 +00:00
2019-11-28 21:20:22 +00:00
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://%s:%s@%s/%s' % (db_user, db_password, db_host, db_name)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
auth = HTTPBasicAuth()
db = SQLAlchemy(app)
2019-11-25 21:52:22 +00:00
2019-11-28 21:20:22 +00:00
@auth.verify_password
def verify_password(username, password):
admin_username = environ.get('ADMIN_USERNAME', 'admin')
admin_password = environ.get('ADMIN_USERNAME', 'secret')
return username is admin_username and password is admin_password
2019-11-25 21:52:22 +00:00
@app.route('/')
def hello_world():
return 'Hello World !'
2019-11-28 21:20:22 +00:00
if __name__ == '__main__':
app_debug = environ.get('FLASK_ENV', 'production') is 'development'
app.run('0.0.0.0', debug=app_debug)