from flask import Flask, request, jsonify
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
db = SQLAlchemy(app)

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data/birds.sqlite'


class Orders(db.Model):
    __tablename__ = 'orders'
    ord = db.Column(db.String, primary_key=True)
    code = db.Column(db.String)
    comment = db.Column(db.String)

    def __init__(self, ord, code, comment):
        self.ord = ord
        self.code = code
        self.comment = comment

    def __repr__(self):
        return "<Orders('{}')>".format(self.ord)


class Families(db.Model):
    __tablename__ = 'families'
    scientific = db.Column(db.String, primary_key=True)
    english = db.Column(db.String, index=True)
    code = db.Column(db.String)
    comment = db.Column(db.String)

    def __init__(self, scientific, english, code, comment):
        self.scientific = scientific
        self.english = english
        self.code = code
        self.comment = comment

    def __repr__(self):
        return "<Families('{} {}')>".format(self.scientific, self.english)


@app.route('/order/', methods=['GET'])
def orders():
  if request.method == 'GET':
    results = Orders.query.limit(100).offset(0).all()
    json_results = []
    for result in results:
        d = {
            'order': result.ord,
            'code': result.code,
            'comment': result.comment
        }
        json_results.append(d)

    return jsonify(items=json_results)


@app.route('/order/<string:order_name>', methods=['GET'])
def order(order_name):
  if request.method == 'GET':
    results = Orders.query.filter(Orders.ord.like("{}%".format(order_name))).all()
    json_results = []

    for result in results:
        d = {
            'order': result.ord,
            'code': result.code,
            'comment': result.comment
        }
        json_results.append(d)

    return jsonify(items=json_results)


@app.route('/family/', methods=['GET'])
def families():
  if request.method == 'GET':
    results = Families.query.limit(100).offset(0).all()
    json_results = []
    for result in results:
        d = {
            'scientific': result.scientific,
            'common': result.english,
            'code': result.code,
            'comment': result.comment
        }
        json_results.append(d)

    return jsonify(items=json_results)


@app.route('/family/scientific/<string:scientific_name>', methods=['GET'])
def family_scientific(scientific_name):
  if request.method == 'GET':
    results = Families.query.filter(Families.scientific.like("{}%".format(scientific_name))).all()
    json_results = []
    for result in results:
        d = {
            'scientific': result.scientific,
            'common': result.english,
            'code': result.code,
            'comment': result.comment
        }
        json_results.append(d)

    return jsonify(items=json_results)


@app.route('/family/common/<string:common_name>', methods=['GET'])
def family_common(common_name):
  if request.method == 'GET':
    results = Families.query.filter(Families.english.like("{}%".format(common_name))).all()
    json_results = []
    for result in results:
        d = {
            'scientific': result.scientific,
            'common': result.english,
            'code': result.code,
            'comment': result.comment
        }
        json_results.append(d)

    return jsonify(items=json_results)


if __name__ == '__main__':
    app.run(debug=True)

@@ -1075,24 +1075,486 @@
 .english)%0A%0A%0A
+class Genera(db.Model):%0A    __tablename__ = 'genera'%0A    genus = db.Column(db.String, primary_key=True)%0A    authority = db.Column(db.String)%0A    code = db.Column(db.String)%0A    comment = db.Column(db.String)%0A%0A    def __init__(self, genus, authority, code, comment):%0A        self.genus = genus%0A        self.authority = authority%0A        self.code = code%0A        self.comment = comment%0A%0A    def __repr__(self):%0A        return %22%3CGenera('%7B%7D')%3E%22.format(self.genus)%0A%0A%0A
 @app.route('
@@ -3880,16 +3880,949 @@
 ults)%0A%0A%0A
+@app.route('/genus/', methods=%5B'GET'%5D)%0Adef genera():%0A  if request.method == 'GET':%0A    results = Genera.query.limit(100).offset(0).all()%0A    json_results = %5B%5D%0A    for result in results:%0A        d = %7B%0A            'genus': result.genus,%0A            'authority': result.authority,%0A            'code': result.code,%0A            'comment': result.comment%0A        %7D%0A        json_results.append(d)%0A%0A    return jsonify(items=json_results)%0A%0A%0A@app.route('/genus/%3Cstring:common_name%3E', methods=%5B'GET'%5D)%0Adef genus_common(common_name):%0A  if request.method == 'GET':%0A    results = Genera.query.filter(Genera.genus.like(%22%7B%7D%25%22.format(common_name))).all()%0A    json_results = %5B%5D%0A    for result in results:%0A        d = %7B%0A            'genus': result.genus,%0A            'authority': result.authority,%0A            'code': result.code,%0A            'comment': result.comment%0A        %7D%0A        json_results.append(d)%0A%0A    return jsonify(items=json_results)%0A%0A%0A
 if __nam

add genus