<commit_before>from flask import Flask, g, session, request, url_for, redirect, flash, \
    render_template
from flask.ext.cache import Cache
from flask.ext.github import GitHub
from flask.ext.sqlalchemy import SQLAlchemy
from raven.contrib.flask import Sentry


db = SQLAlchemy()
cache = Cache()
github = GitHub()


def create_app(config):
    from pypi_notifier.views import register_views
    from pypi_notifier.models import User

    app = Flask(__name__)
    load_config(app, config)

    db.init_app(app)
    cache.init_app(app)
    github.init_app(app)

    register_views(app)

    if app.config.get('SENTRY_DSN'):
        Sentry(app)

    @app.before_request
    def set_user():
        g.user = None
        if session.get('user_id', None):
            g.user = User.query.get(session['user_id'])

    @app.after_request
    def remove_session(response):
        db.session.remove()
        return response

    @github.access_token_getter
    def get_github_token():
        user = g.user
        if user is not None:
            return user.github_token

    @app.route('/github-callback')
    @github.authorized_handler
    def oauth_authorized(resp):
        next_url = request.args.get('next') or url_for('repos')

        if resp is None:
            flash('You denied the request to sign in.')
            return redirect(next_url)

        token = resp['access_token']
        user_response = github.get('user', params={'access_token': token})
        github_id = user_response['id']
        user = User.query.filter_by(github_token=token).first()
        if user is None:
            user = User.query.filter_by(github_id=github_id).first()
        if user is None:
            user = User(token)
            db.session.add(user)

        user.github_token = token
        user.github_id = github_id
        user.name = user_response['login']
        user.email = user_response['email']<commit_msg>update callback method<commit_after>from flask import Flask, g, session, request, url_for, redirect, flash, \
    render_template
from flask.ext.cache import Cache
from flask.ext.github import GitHub
from flask.ext.sqlalchemy import SQLAlchemy
from raven.contrib.flask import Sentry


db = SQLAlchemy()
cache = Cache()
github = GitHub()


def create_app(config):
    from pypi_notifier.views import register_views
    from pypi_notifier.models import User

    app = Flask(__name__)
    load_config(app, config)

    db.init_app(app)
    cache.init_app(app)
    github.init_app(app)

    register_views(app)

    if app.config.get('SENTRY_DSN'):
        Sentry(app)

    @app.before_request
    def set_user():
        g.user = None
        if session.get('user_id', None):
            g.user = User.query.get(session['user_id'])

    @app.after_request
    def remove_session(response):
        db.session.remove()
        return response

    @github.access_token_getter
    def get_github_token():
        user = g.user
        if user is not None:
            return user.github_token

    @app.route('/github-callback')
    @github.authorized_handler
    def oauth_authorized(token):
        next_url = request.args.get('next') or url_for('repos')

        if token is None:
            flash('You denied the request to sign in.')
            return redirect(next_url)

        user_response = github.get('user', params={'access_token': token})
        github_id = user_response['id']
        user = User.query.filter_by(github_token=token).first()
        if user is None:
            user = User.query.filter_by(github_id=github_id).first()
        if user is None:
            user = User(token)
            db.session.add(user)

        user.github_token = token
        user.github_id = github_id
        user.name = user_response['login']
        user.email = user_response['email']
{'fraction_non_alphanumeric': 0.10309548793284365, 'fraction_numerical': 0.0, 'mean_word_length': 2.6453154875717018, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4006886', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1140, 'n_words': 267}