<commit_before>from decouple import config
from flask import Flask, redirect, render_template, request

try:
    from urlparse import urljoin
except ImportError:
    from urllib.parse import urljoin

S3_BUCKET = config('S3_BUCKET')
REDIRECT_URL = config('REDIRECT_URL')
OG_TITLE = config('OG_TITLE')
OG_DESCRIPTION = config('OG_DESCRIPTION')

S3_ROOT = 'https://s3.amazonaws.com/'

app = Flask(__name__)


def is_facebook(ua):
    return ua.startswith('facebookexternalhit') or ua == 'Facebot'


@app.route("/<path:path>", methods=['GET'])
def opengraph(path):

    ua = request.headers.get('User-Agent')

    if is_facebook(ua) or 'fb' in request.args:

        context = {
            'og_title': OG_TITLE,
            'og_description': OG_DESCRIPTION,
            'og_image': urljoin(S3_ROOT, '{}/{}'.format(S3_BUCKET, path)),
            'og_url': '/{}'.format(path),
        }
        return render_template('opengraph.html', **context)

    else:

        return redirect(REDIRECT_URL)


if __name__ == "__main__":
    DEBUG = config('DEBUG', default=False, cast=bool)
    PORT = config('PORT', default=8000, cast=int)
    app.run(debug=DEBUG, port=PORT)
<commit_msg>use base_url as og_url<commit_after>from decouple import config
from flask import Flask, redirect, render_template, request

try:
    from urlparse import urljoin
except ImportError:
    from urllib.parse import urljoin

S3_BUCKET = config('S3_BUCKET')
REDIRECT_URL = config('REDIRECT_URL')
OG_TITLE = config('OG_TITLE')
OG_DESCRIPTION = config('OG_DESCRIPTION')

S3_ROOT = 'https://s3.amazonaws.com/'

app = Flask(__name__)


def is_facebook(ua):
    return ua.startswith('facebookexternalhit') or ua == 'Facebot'


@app.route("/<path:path>", methods=['GET'])
def opengraph(path):

    ua = request.headers.get('User-Agent')

    if is_facebook(ua) or 'fb' in request.args:

        context = {
            'og_title': OG_TITLE,
            'og_description': OG_DESCRIPTION,
            'og_image': urljoin(S3_ROOT, '{}/{}'.format(S3_BUCKET, path)),
            'og_url': request.base_url,
        }
        return render_template('opengraph.html', **context)

    else:

        return redirect(REDIRECT_URL)


if __name__ == "__main__":
    DEBUG = config('DEBUG', default=False, cast=bool)
    PORT = config('PORT', default=8000, cast=int)
    app.run(debug=DEBUG, port=PORT)

{'fraction_non_alphanumeric': 0.1389715257118572, 'fraction_numerical': 0.008499787505312367, 'mean_word_length': 3.7364185110663986, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '7667107', 'n_tokens_mistral': 821, 'n_tokens_neox': 806, 'n_words': 169}