<commit_before>import flask
import psycopg2

app = flask.Flask(__name__)
db = psycopg2.connect('postgres://rpitours:rpitours@localhost:5432/rpitours')

def make_tour():
	tour = {
		'id': 1,
		'name': '<NAME>',
		'waypoints': [
			(5, 2),
			(2, 3),
			(1, 4),
			(4, 4)
		],
		'landmarks': [
			{
				'name': 'A Place',
				'description': 'This is a description of this place.',
				'photos': ['https://example.com/photo1.jpg', 'https://example.com/photo2.jpg'],
				'coordinate': (3, 4),
			}, {
				'coordinate': (2, 3),
			}, {
				'coordinate': (4, 1)
			}
		]
	}
	return tour

@app.route('/')
def index():
	return flask.jsonify(hello='world')

@app.route('/tours')
def tours():
	tour_lst = [make_tour()]
	return flask.jsonify(tours=tour_lst)

if __name__ == '__main__':
	app.run(debug=True)<commit_msg>Move database connection code into thread-local context<commit_after>import flask
import psycopg2

DB_URL = 'postgres://rpitours:rpitours@localhost:5432/rpitours'

app = flask.Flask(__name__)

def get_db():
	db = getattr(flask.g, 'database', None)
	if db is None:
		db = flask.g.database = psycopg2.connect(DB_URL)
	return db

def make_tour():
	tour = {
		'id': 1,
		'name': '<NAME>',
		'waypoints': [
			(5, 2),
			(2, 3),
			(1, 4),
			(4, 4)
		],
		'landmarks': [
			{
				'name': 'A Place',
				'description': 'This is a description of this place.',
				'photos': ['https://example.com/photo1.jpg', 'https://example.com/photo2.jpg'],
				'coordinate': (3, 4),
			}, {
				'coordinate': (2, 3),
			}, {
				'coordinate': (4, 1)
			}
		]
	}
	return tour

@app.route('/')
def index():
	return flask.jsonify(hello='world')

@app.route('/tours')
def tours():
	tour_lst = [make_tour()]
	return flask.jsonify(tours=tour_lst)

@app.route('/dbtest')
def dbtest():
	get_db()
	return flask.jsonify(success=True)

if __name__ == '__main__':
	app.run(debug=True)
{'fraction_non_alphanumeric': 0.20268817204301076, 'fraction_numerical': 0.024731182795698924, 'mean_word_length': 3.629353233830846, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '439089', 'n_tokens_mistral': 866, 'n_tokens_neox': 741, 'n_words': 158}