pbr-ayct-backend/ayct_backend/__init__.py

33 lines
1.1 KiB
Python
Raw Normal View History

2022-01-24 19:37:27 +01:00
import os
2022-01-31 17:21:23 +01:00
from flask import Flask, request
2022-01-24 20:26:12 +01:00
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
2022-01-24 20:06:33 +01:00
#import pbrAyctCore.core as core
2021-12-01 14:25:42 +01:00
def create_app():
app = Flask('ayct-backend')
2022-01-24 19:37:27 +01:00
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY')
2022-01-24 21:41:18 +01:00
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
2022-01-24 19:37:27 +01:00
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)
2022-01-24 21:52:38 +01:00
twitter_db.create_all(app=app)
2022-01-24 23:20:49 +01:00
campaign_db.create_all(app=app)
2022-01-24 21:41:18 +01:00
2022-01-24 19:37:27 +01:00
app.register_blueprint(twitter, url_prefix='/twitter')
app.register_blueprint(campaign, url_prefix='/campaign')
2021-12-01 14:25:42 +01:00
@app.route('/hello')
def hello():
2022-01-24 20:06:33 +01:00
return "Hello world!"
2021-12-01 14:25:42 +01:00
return app