Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flaskenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FLASK_APP=system.app
FLASK_ENV=development
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__pycache__/
.idea/
.vscode/
venv/
app.db
environ.sh
db.sqlite3
.env
7 changes: 3 additions & 4 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
web: python webhook.py
init: python manage.py db init
migrate: python manage.py db migrate
upgrade: python manage.py db upgrade
web: flask run
webhook: flask webhook
upgrade: flask db upgrade
17 changes: 0 additions & 17 deletions config.py

This file was deleted.

14 changes: 0 additions & 14 deletions manage.py

This file was deleted.

12 changes: 0 additions & 12 deletions math_bot/app.py

This file was deleted.

Empty file modified migrations/README
100755 → 100644
Empty file.
38 changes: 23 additions & 15 deletions migrations/env.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig

import logging
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool

from alembic import context

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down Expand Up @@ -41,7 +45,9 @@ def run_migrations_offline():

"""
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url)
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True
)

with context.begin_transaction():
context.run_migrations()
Expand All @@ -65,21 +71,23 @@ def process_revision_directives(context, revision, directives):
directives[:] = []
logger.info('No changes in schema detected.')

engine = engine_from_config(config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool,
)

connection = engine.connect()
context.configure(connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args)
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
)

try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()


if context.is_offline_mode():
run_migrations_offline()
Expand Down
Empty file modified migrations/script.py.mako
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""empty message

Revision ID: 1ccf08c974d4
Revision ID: f417e7b610f4
Revises:
Create Date: 2018-03-01 00:52:29.279182
Create Date: 2019-02-28 16:20:39.378017

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '1ccf08c974d4'
revision = 'f417e7b610f4'
down_revision = None
branch_labels = None
depends_on = None
Expand Down
13 changes: 0 additions & 13 deletions polling.py

This file was deleted.

47 changes: 23 additions & 24 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
alembic==0.9.8
certifi==2017.11.5
alembic==1.0.7
asn1crypto==0.24.0
certifi==2018.11.29
cffi==1.12.1
chardet==3.0.4
click==6.7
Flask==0.12.2
Flask-Migrate==2.1.1
Flask-Script==2.0.6
Click==7.0
cryptography==2.5
Flask==1.0.2
Flask-Migrate==2.4.0
Flask-SQLAlchemy==2.3.2
future==0.16.0
idna==2.6
inflect==0.2.5
itsdangerous==0.24
jaraco.itertools==2.1
future==0.17.1
idna==2.8
itsdangerous==1.1.0
Jinja2==2.10
Mako==1.0.7
MarkupSafe==1.0
more-itertools==4.0.1
nginxparser-eb==0.0.9
psycopg2==2.7.4
pyparsing==2.2.0
python-dateutil==2.6.1
python-editor==1.0.3
python-telegram-bot==10.0.1
requests==2.18.4
six==1.11.0
SQLAlchemy==1.2.4
urllib3==1.22
MarkupSafe==1.1.1
psycopg2==2.7.7
pycparser==2.19
python-dateutil==2.8.0
python-dotenv==0.10.1
python-editor==1.0.4
python-telegram-bot==11.1.0
requests==2.21.0
six==1.12.0
SQLAlchemy==1.2.18
urllib3==1.24.1
Werkzeug==0.14.1
xmltodict==0.11.0
xmltodict==0.12.0
File renamed without changes.
19 changes: 19 additions & 0 deletions system/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from flask import Flask

from system.db import db, migrate
from system.blueprints import register_blueprints
from system.commands import register_commands


def create_app():
app = Flask(__name__)
app.url_map.strict_slashes = False
app.config.from_object('system.config')

db.app = app
db.init_app(app)
migrate.init_app(app, db)
register_blueprints(app)
register_commands(app)

return app
9 changes: 9 additions & 0 deletions system/blueprints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from system.routes import system_blueprint


def register_blueprints(app):
with app.app_context():
app.register_blueprint(system_blueprint)

from telegram_bot.routes import telegram_blueprint
app.register_blueprint(telegram_blueprint, url_prefix='/telegram')
23 changes: 23 additions & 0 deletions system/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import click

from flask.cli import with_appcontext

import telegram_bot.polling
import telegram_bot.webhook


@click.command('polling')
@with_appcontext
def start_polling():
telegram_bot.polling.start_polling()


@click.command('webhook')
@with_appcontext
def start_webhook():
telegram_bot.webhook.set_webhook()


def register_commands(app):
app.cli.add_command(start_polling)
app.cli.add_command(start_webhook)
15 changes: 15 additions & 0 deletions system/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import dotenv


BASE_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
dotenv.load_dotenv(BASE_DIR)

HOST_URL = os.getenv('HOST_URL')

TELEGRAM_TOKEN = os.getenv('TELEGRAM_TOKEN')
WOLFRAM_APP_ID = os.getenv('WOLFRAM_APP_ID')

SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL') or \
'sqlite:///%s' % os.path.join(BASE_DIR, 'db.sqlite3')
SQLALCHEMY_TRACK_MODIFICATIONS = False
6 changes: 6 additions & 0 deletions system/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate


db = SQLAlchemy()
migrate = Migrate()
9 changes: 9 additions & 0 deletions system/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from flask import Blueprint


system_blueprint = Blueprint('system_routes', __name__)


@system_blueprint.route('/')
def index():
return 'It works'
Empty file added telegram_bot/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions telegram_bot/blueprint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from flask import Blueprint

from utils.singleton import Singleton


@Singleton
class TelegramBlueprint(Blueprint):
def __init__(self, *args):
super().__init__('telegram_blueprint', __name__, *args)
8 changes: 8 additions & 0 deletions telegram_bot/bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from telegram import Bot

from utils.singleton import Singleton


@Singleton
class TelegramBot(Bot):
pass
Loading