<commit_before># -*- coding: utf-8 -*-
import sys, os

gtfslibpath = os.path.join(os.getcwd(), 'gtfslib-python')
sys.path.append(gtfslibpath)

from flask import Flask, request, abort, jsonify
from services import upload_gtfs
from services.display_routes import get_routes
from services.display_agencies import get_agencies
from database.database_access import init_db
from services.display_insee import get_insee
from services.check_urban import get_urban_status
from services.display_routes_details import get_routes_details

app = Flask(__name__)

def error(message):
    return jsonify({"error": message}), 400

@app.route("/agencies", methods=['GET'])
def display_agencies():
	return jsonify({"agencies": get_agencies()})


# Example curl -i -H "Content-Type: application/octet-stream" -X POST --data-binary @nantes.zip http://localhost:5000/upload/gtfs
@app.route("/upload/gtfs", methods=['PUT', 'POST'])
def upload_file():
    if request.headers['Content-Type'] != 'application/octet-stream':
        abort(400)
    filename = upload_gtfs.savefile(request.data)
    errormsg = upload_gtfs.add_gtfs_to_db(filename)
    
    if errormsg:
        return error(errormsg)
    
    return jsonify({"status": 201}), 201 


@app.route("/agencies/<int:agency_id>/routes", methods=['GET'])
def display_routes(agency_id):
    try:
        return jsonify({'data': get_routes(agency_id)})
    except Exception as e:
        return error(str(e))

@app.route("/agencies/<int:agency_id>/routes/urban", methods=['GET'])
def display_urban(agency_id):
    try:
        return jsonify({ "routes": get_urban_status(agency_id)})
    except Exception as e:
        return error(str(e))

@app.route("/agencies/<int:agency_id>/routes/details", methods=['GET'])
def display_details(agency_id):
    # try:
    #     return jsonify({ "routes": get_routes_details(agency_id, 6)})
    # except Exception as e:
    #     return error(str(e))
    return jsonify({ "routes": get_routes_details(agency_id, 6)})


@app.route("/insee", methods=['GET'])
def display_insee():
	return jsonify({ "population": get_insee()})


if __name__ == "__main__":
    init_db()
    app.run(host='0.0.0.0', debug=True)<commit_msg>ajout du cross origin<commit_after># -*- coding: utf-8 -*-
import sys, os

gtfslibpath = os.path.join(os.getcwd(), 'gtfslib-python')
sys.path.append(gtfslibpath)

from flask import Flask, request, abort, jsonify
from services import upload_gtfs
from services.display_routes import get_routes
from services.display_agencies import get_agencies
from database.database_access import init_db
from services.display_insee import get_insee
from services.check_urban import get_urban_status
from services.display_routes_details import get_routes_details
from flask.ext.cors import CORS

app = Flask(__name__)
CORS(app)

def error(message):
    return jsonify({"error": message}), 400

@app.route("/agencies", methods=['GET'])
def display_agencies():
	return jsonify({"agencies": get_agencies()})


# Example curl -i -H "Content-Type: application/octet-stream" -X POST --data-binary @nantes.zip http://localhost:5000/upload/gtfs
@app.route("/upload/gtfs", methods=['PUT', 'POST'])
def upload_file():
    if request.headers['Content-Type'] != 'application/octet-stream':
        abort(400)
    filename = upload_gtfs.savefile(request.data)
    errormsg = upload_gtfs.add_gtfs_to_db(filename)
    
    if errormsg:
        return error(errormsg)
    
    return jsonify({"status": 201}), 201 


@app.route("/agencies/<int:agency_id>/routes", methods=['GET'])
def display_routes(agency_id):
    try:
        return jsonify({'data': get_routes(agency_id)})
    except Exception as e:
        return error(str(e))

@app.route("/agencies/<int:agency_id>/routes/urban", methods=['GET'])
def display_urban(agency_id):
    try:
        return jsonify({ "routes": get_urban_status(agency_id)})
    except Exception as e:
        return error(str(e))

@app.route("/agencies/<int:agency_id>/routes/details", methods=['GET'])
def display_details(agency_id):
    # try:
    #     return jsonify({ "routes": get_routes_details(agency_id, 6)})
    # except Exception as e:
    #     return error(str(e))
    return jsonify({ "routes": get_routes_details(agency_id, 6)})


@app.route("/insee", methods=['GET'])
def display_insee():
	return jsonify({ "population": get_insee()})


if __name__ == "__main__":
    init_db()
    #app.run(host='0.0.0.0', debug=True)
    app.run(debug=True)
{'fraction_non_alphanumeric': 0.14652261985145174, 'fraction_numerical': 0.010353364843574162, 'mean_word_length': 4.675606641123882, 'pattern_counts': {'":': 16, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5402612', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1491, 'n_words': 320}