<commit_before># code for mongodb

from flask import Flask, jsonify, request, json, abort, render_template
from flask_pymongo import PyMongo
from flask_restplus import Resource
from bson import json_util
from bson.objectid import ObjectId

app = Flask(__name__)

# connect to plannerdb in external database
app.config['MONGO_DBNAME'] = 'plannerdb'
app.config['MONGO_URI'] = 'mongodb://meealo:<EMAIL>:39904/plannerdb'

mongo = PyMongo(app)

# dumps mongo data object as json
def toJson(data):
	return json.dumps(data, default=json_util.default)

# test that the index uri works
@app.route('/')
def hello():
#	mongo.db.users.create_index("email", unique=True)
	meals = get_all_meals()
	return render_template('index.html', meals=meals)

# meal data section
@app.route('/meals', methods=['GET'])
def get_all_meals():
	meals = mongo.db.meals
	output = []
	for m in meals.find():
		output.append(m)
	return output
	
@app.route('/meals/<meal_id>', methods=['GET'])
def get_meal(meal_id):
	meals = mongo.db.meals
	meal = meals.find_one({'_id' : ObjectId(meal_id)})
	return toJson(meal)

# add a new meal to the database
# requires ingredients list to be separated by a -- and recipe steps by --
# can be changed later if a better delimiter is thought of
@app.route('/meals', methods=['POST'])
def add_meal():
	meals = mongo.db.meals
	ingredients = [y for y in (x.strip() for x in request.form['ingredients'].split('--')) if y]
	recipe = [y for y in (x.strip() for x in request.form['recipe'].split('--')) if y]
	meal = meals.insert_one({
		'name' : request.form['name'],
		'cuisine' : request.form['cuisine'],
		'difficulty' : request.form['difficulty'],
		'total_cooking_time' : request.form['total_cooking_time'],
		'ingredients' : ingredients,<commit_msg>Update meealo.py<commit_after># code for mongodb

from flask import Flask, jsonify, request, json, abort, render_template
from flask_pymongo import PyMongo
from flask_restplus import Resource
from bson import json_util
from bson.objectid import ObjectId

app = Flask(__name__)

# connect to plannerdb in external database
app.config['MONGO_DBNAME'] = 'plannerdb'
app.config['MONGO_URI'] = 'mongodb://meealo:<EMAIL>:39904/plannerdb'

mongo = PyMongo(app)

# dumps mongo data object as json
def toJson(data):
	return json.dumps(data, default=json_util.default)

# test that the index uri works
@app.route('/')
def hello():
#	mongo.db.users.create_index("email", unique=True)
	meals = get_all_meals()
	return render_template('index.html', meals=meals)

def get_all_meals():
	meals = mongo.db.meals
	output = []
	for m in meals.find():
		output.append(m)
	return output

# meal data section
@app.route('/meals', methods=['GET'])
def get_all_meals_JSON():
	meals = mongo.db.meals
	output = []
	for m in meals.find():
		output.append(m)
	return toJson(output)
	
@app.route('/meals/<meal_id>', methods=['GET'])
def get_meal(meal_id):
	meals = mongo.db.meals
	meal = meals.find_one({'_id' : ObjectId(meal_id)})
	return toJson(meal)

# add a new meal to the database
# requires ingredients list to be separated by a -- and recipe steps by --
# can be changed later if a better delimiter is thought of
@app.route('/meals', methods=['POST'])
def add_meal():
	meals = mongo.db.meals
	ingredients = [y for y in (x.strip() for x in request.form['ingredients'].split('--')) if y]
	recipe = [y for y in (x.strip() for x in request.form['recipe'].split('--')) if y]
	meal = meals.insert_one({
		'name' : request.form['name'],
		'cuisine' : request.form['cuisine'],
		'difficulty' : request.form['difficulty'],
		'total_cooking_time' : request.form['total_cooking_time'],
		'ingredients' : ingredients,
{'fraction_non_alphanumeric': 0.1466299862448418, 'fraction_numerical': 0.002751031636863824, 'mean_word_length': 5.090452261306533, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6042742', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1277, 'n_words': 352}