<commit_before>import json

from flask import Flask, jsonify, request, Response
from flaskext.mongoalchemy import MongoAlchemy


ENDPOINT = 'http://data.nasa.gov/api/'

app = Flask(__name__)
app.config['MONGOALCHEMY_DATABASE'] = 'nasadata'
db = MongoAlchemy(app)

# These imports must be below the db definition
from api.parsers import datanasa
from api.parsers.datanasa import Dataset, Tag
from api.parsers import grin
from api.parsers import kepler

# FIXME: Need to call an 'update' function which loops and gets each dataset
datanasa.get_dataset(619)

def hacky_jsonify_list(data_list):
    return Response(json.dumps(data_list), mimetype='application/json')

@app.route('/', methods=['GET'])
def index():
    datasets = datanasa.Dataset.query.all()
    response = []
    for dataset in datasets:
        print "x"
        response.append(dataset.data)
    return jsonify(response)


@app.route('/get_recent_datasets')
def get_recent_datasets():
    count = request.args.get('count', 10) # default to 10 results
    results = [dataset.data for dataset in Dataset.query.filter_by_recentness(count)]
    return hacky_jsonify_list(results)

@app.route('/get_dataset/<identifier>')
def get_dataset(identifier):
    try:
        pk = int(identifier)
        response = Dataset.query.get_by_remote_id(pk)<commit_msg>Let the comments begin<commit_after>import json

from flask import Flask, jsonify, request, Response
from flaskext.mongoalchemy import MongoAlchemy


ENDPOINT = 'http://data.nasa.gov/api/'

app = Flask(__name__)
app.config['MONGOALCHEMY_DATABASE'] = 'nasadata'
db = MongoAlchemy(app)

# These imports must be below the db definition
from api.parsers import datanasa
from api.parsers.datanasa import Dataset, Tag
from api.parsers import grin
from api.parsers import kepler

# FIXME: Need to call an 'update' function which loops and gets each dataset
datanasa.get_dataset(619)

def hacky_jsonify_list(data_list):
    # this can be replaced by providing a serialization methods on the Dataset
    # and the DatasetQuery objects
    return Response(json.dumps(data_list), mimetype='application/json')

@app.route('/', methods=['GET'])
def index():
    datasets = datanasa.Dataset.query.all()
    response = []
    for dataset in datasets:
        print "x"
        response.append(dataset.data)
    return jsonify(response)


@app.route('/get_recent_datasets')
def get_recent_datasets():
    count = request.args.get('count', 10) # default to 10 results
    results = [dataset.data for dataset in Dataset.query.filter_by_recentness(count)]
    return hacky_jsonify_list(results)

@app.route('/get_dataset/<identifier>')
def get_dataset(identifier):
    try:
        pk = int(identifier)
        response = Dataset.query.get_by_remote_id(pk)
{'fraction_non_alphanumeric': 0.10468920392584515, 'fraction_numerical': 0.005089058524173028, 'mean_word_length': 4.526104417670683, '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': '568944', 'n_tokens_mistral': 900, 'n_tokens_neox': 864, 'n_words': 232}