<commit_before>import sqlite3
from flask import Flask, render_template, request, g, redirect

# configuration
DATABASE = 'shorten.db'
DEBUG = True
SECRET_KEY = 'mysecret'
USERNAME = 'root'
PASSWORD = 'password'

app = Flask(__name__)


@app.route("/")
def index():
    return render_template('form.html')


@app.route("/shorten", methods=['POST'])
def shorten():
    long_url = request.form['url']
    existing_url_record = query_db('select short from shorten where url = ?', (long_url,), one=True)
    if existing_url_record is None:
        short_url = shorten_url(3)
        insert_db('shorten', ('url', 'short'), (long_url, short_url))
    else:
        short_url = existing_url_record[0]

    return render_template('shortened.html', url=long_url, short=short_url)


@app.route('/<short_url>')
def catch_all(short_url):
    existing_url_record = query_db('select url from shorten where short = ?', (short_url,), one=True)
    if existing_url_record is None:
        long_url = '/'
    else:
        long_url = existing_url_record[0]
    return redirect(long_url, code=302)


def shorten_url(x):
    import string, random
    return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(x))


def connect_db():
    return sqlite3.connect('shorten.db')


def get_db():<commit_msg>Clean up imports<commit_after>import sqlite3
import string
import random
from flask import Flask, render_template, request, g, redirect

# configuration
DATABASE = 'shorten.db'
DEBUG = True
SECRET_KEY = 'mysecret'
USERNAME = 'root'
PASSWORD = 'password'

app = Flask(__name__)


@app.route("/")
def index():
    return render_template('form.html')


@app.route("/shorten", methods=['POST'])
def shorten():
    long_url = request.form['url']
    existing_url_record = query_db('select short from shorten where url = ?', (long_url,), one=True)
    if existing_url_record is None:
        short_url = shorten_url(3)
        insert_db('shorten', ('url', 'short'), (long_url, short_url))
    else:
        short_url = existing_url_record[0]

    return render_template('shortened.html', url=long_url, short=short_url)


@app.route('/<short_url>')
def catch_all(short_url):
    existing_url_record = query_db('select url from shorten where short = ?', (short_url,), one=True)
    if existing_url_record is None:
        long_url = '/'
    else:
        long_url = existing_url_record[0]
    return redirect(long_url, code=302)


def shorten_url(x):
    return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(x))


def connect_db():
    return sqlite3.connect('shorten.db')


def get_db():
{'fraction_non_alphanumeric': 0.13356295445847685, 'fraction_numerical': 0.006123230003827019, 'mean_word_length': 4.33469387755102, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6555073', 'n_tokens_mistral': 899, 'n_tokens_neox': 860, 'n_words': 204}