Beispiel #1
0
def send_congrats(conn: connection, slack_client: SlackClient):
    dbx = pictures.connect_dbx()
    recipients = todays_recipients(conn)
    log.info(f"Recipients today {recipients}")
    for recipient in recipients:
        greet = formulate_congrat(recipient, conn, dbx)
        task.send_response(slack_client, greet, channel=config.main_channel)
Beispiel #2
0
def setup() -> t.Tuple[SlackClient, Dropbox, connection]:
    conn = database.connect()

    dbx = pictures.connect_dbx()

    slack_client = SlackClient(config.slack_bot_user_token)
    connected = slack_client.rtm_connect()
    if not connected:
        raise Exception("Connection failed. Invalid Slack token or bot ID?")

    return slack_client, dbx, conn
Beispiel #3
0
def send_congrats() -> None:  # no test coverage
    dbx = pictures.connect_dbx()
    conn = database.connect()
    recipients = todays_recipients(conn)
    if not recipients:
        return
    log.info(f"Recipients today {recipients}")
    slack_client = slack.WebClient(config.slack_bot_user_token)
    for recipient in recipients:
        greet = formulate_congrat(recipient, conn, dbx)
        commands.send_response(slack_client,
                               greet,
                               channel=config.main_channel)
Beispiel #4
0
def main(options: t.Optional[dict], debug: bool = False):
    try:
        app.pool.setup()
        with app.pool.get_connection() as conn:
            pictures.queries.define_args(conn)
            conn.commit()
        app.dbx = pictures.connect_dbx()
        if debug is False:
            gunicorn_app = StandaloneApplication(app, options)
            gunicorn_app.run()
        else:
            # Workaround for a werzeug reloader bug
            # (https://github.com/pallets/flask/issues/1246)
            os.environ["PYTHONPATH"] = os.getcwd()
            app.run(debug=True)
    except Exception:
        log.error("Error in server setup", exc_info=True)
    finally:
        if app.pool.is_setup:
            app.pool.closeall()