40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
import os
|
|
from flask import Flask, request
|
|
from ayct_backend.twitter import twitter
|
|
from ayct_backend.twitter.models import twitter_db
|
|
from ayct_backend.campaign import campaign
|
|
from ayct_backend.campaign.models import campaign_db
|
|
#import pbrAyctCore.core as core
|
|
|
|
def create_app():
|
|
app = Flask('ayct-backend')
|
|
|
|
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY')
|
|
database_uri = os.getenv('DATABASE_URL')
|
|
if database_uri and database_uri.startswith("postgres://"):
|
|
database_uri = database_uri.replace("postgres://", "postgresql://", 1)
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = database_uri
|
|
app.config['TWITTER_CONSUMER_KEY'] = os.getenv('TWITTER_CONSUMER_KEY')
|
|
app.config['TWITTER_CONSUMER_SECERT'] = os.getenv('TWITTER_CONSUMER_SECERT')
|
|
|
|
twitter_db.init_app(app)
|
|
campaign_db.init_app(app)
|
|
|
|
twitter_db.drop_all(app=app)
|
|
twitter_db.create_all(app=app)
|
|
twitter_db.drop_all(app=app)
|
|
campaign_db.create_all(app=app)
|
|
|
|
app.register_blueprint(twitter, url_prefix='/twitter')
|
|
app.register_blueprint(campaign, url_prefix='/campaign')
|
|
|
|
@app.before_request
|
|
def log_request_info():
|
|
app.logger.debug('Headers: %s', request.headers)
|
|
app.logger.debug('Body: %s', request.get_data())
|
|
|
|
@app.route('/hello')
|
|
def hello():
|
|
return "Hello world!"
|
|
|
|
return app |