add project skeleton code

main
lza_menace 3 years ago
parent eee6e17037
commit 566f631bf6

3
.gitignore vendored

@ -127,3 +127,6 @@ dmypy.json
# Pyre type checker # Pyre type checker
.pyre/ .pyre/
# Data
data/

@ -0,0 +1,20 @@
setup:
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
shell:
bash manage.sh shell
dev:
bash manage.sh run
prod:
bash manage.sh prod
huey:
mkdir -p data/
.venv/bin/huey_consumer suchwowx.tasks.huey -w 1 -v | tee -a data/huey.log
kill:
pkill -e -f huey
pkill -e -f suchwowx

@ -0,0 +1,31 @@
#!/bin/bash
source .venv/bin/activate
export FLASK_APP=suchwowx/app.py
export FLASK_SECRETS=config.py
export FLASK_DEBUG=1
export FLASK_ENV=development
# override
export $(cat .env)
if [[ ${1} == "prod" ]];
then
export BASE=./data/gunicorn
export FLASK_ENV=production
export FLASK_DEBUG=0
mkdir -p $BASE
pgrep -F $BASE/gunicorn.pid
if [[ $? != 0 ]]; then
gunicorn \
--bind 127.0.0.1:4000 "suchwowx.app:app" \
--daemon \
--log-file $BASE/gunicorn.log \
--pid $BASE/gunicorn.pid \
--reload
sleep 2
echo "Started gunicorn on 127.0.0.1:4000 with pid $(cat $BASE/gunicorn.pid)"
fi
else
flask $@
fi

@ -0,0 +1,14 @@
arrow
Flask
Flask-WTF
Flask-SQLAlchemy
Flask-Mobility
peewee
gunicorn
huey
redis
Pillow
ipfshttpclient
python-dotenv
requests
web3

@ -0,0 +1,12 @@
from logging.config import dictConfig
from suchwowx.factory import create_app
from suchwowx import config
app = create_app()
dictConfig(config.LOGGING_CONFIG)
if __name__ == '__main__':
app.run()

@ -0,0 +1,56 @@
from os import getenv
from dotenv import load_dotenv
load_dotenv()
# App
SECRET_KEY = getenv('SECRET_KEY', 'yyyyyyyyyyyyy') # whatever you want it to be
DATA_FOLDER = getenv('DATA_FOLDER', '/path/to/uploads') # some stable storage path
SERVER_NAME = getenv('SERVER_NAME', '127.0.0.1:5000') # name of your DNS resolvable site (.com)
# Cache
CACHE_HOST = getenv('CACHE_HOST', 'localhost')
CACHE_PORT = getenv('CACHE_PORT', 6379)
# Uploads
SESSION_TYPE = 'filesystem'
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'svg', 'mp4', 'webp'}
MAX_CONTENT_LENGTH = 32 * 1024 * 1024
TEMPLATES_AUTO_RELOAD = getenv('TEMPLATES_AUTO_RELOAD', True)
# Logging
LOGGING_CONFIG = {
'version': 1,
'formatters': {'default': {
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
}},
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'default',
'stream': 'ext://sys.stdout',
},
'wsgi': {
'class': 'logging.StreamHandler',
'stream': 'ext://flask.logging.wsgi_errors_stream',
'formatter': 'default'
}
},
'loggers': {
'gunicorn.error': {
'handlers': ['console'],
'level': 'INFO',
'propagate': False,
},
'gunicorn.access': {
'handlers': ['console'],
'level': 'INFO',
'propagate': False,
}
},
'root': {
'level': 'DEBUG',
'handlers': ['console'],
}
}

@ -0,0 +1,36 @@
from logging.config import dictConfig
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_mobility import Mobility
from suchwowx import config
db = SQLAlchemy()
def setup_db(app: Flask, db:SQLAlchemy=db):
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite://{config.DATA_FOLDER}/sqlite.db' # noqa
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
return db
def create_app_huey():
app = Flask(__name__)
db = SQLAlchemy()
dictConfig(config.LOGGING_CONFIG)
setup_db(app, db)
return app
def create_app():
app = Flask(__name__)
app.config.from_envvar('FLASK_SECRETS')
setup_db(app)
Mobility(app)
with app.app_context():
from suchwowx import filters, routes
app.register_blueprint(filters.bp)
app.register_blueprint(routes.bp)
return app

@ -0,0 +1,15 @@
from flask import Blueprint
from arrow import get as arrow_get
bp = Blueprint('filters', 'filters')
@bp.app_template_filter('shorten_address')
def shorten_address(a):
_p = a[0:4]
_s = a[-4:]
return f'{_p}...{_s}'
@bp.app_template_filter('humanize')
def humanize(d):
return arrow_get(d).humanize()

@ -0,0 +1,13 @@
from uuid import uuid4
from suchwowx.factory import db
def rand_id():
return uuid4().hex
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)

@ -0,0 +1,8 @@
from flask import Blueprint
bp = Blueprint('meta', 'meta')
@bp.route('/')
def index():
return 'interplanetary memes'

@ -0,0 +1,12 @@
from huey import RedisHuey
from suchwowx.factory import create_app_huey
from suchwowx import config
huey = RedisHuey(
host=config.CACHE_HOST,
port=config.CACHE_PORT
)
app = create_app_huey()
Loading…
Cancel
Save