<commit_before>from flask import jsonify
from flask.ext.restful import Resource
from serializers import ActivitySerializer, ScoreSerializer, TagSerializer, \
    UserSerializer
import models


# Will be set by api.create_app()
db = None


class User(Resource):
    def get(self, id):
        q = db.session.query
        result = q(models.User).get(id)
        result = UserSerializer(result).data
        return jsonify(result=result)

    def put(self, id):
        pass

    def delete(self, id):
        pass


class Activity(Resource):
    def get(self, id):
        q = db.session.query
        result = q(models.Activity).get(id)
        result = ActivitySerializer(result).data
        return jsonify(result=result)

    def put(self, id):
        pass

    def delete(self, id):
        pass


class Activities(Resource):
    def get(self):
        q = db.session.query
        result = q(models.Activity).all()
        result = [ActivitySerializer(r).data for r in result]
        return jsonify(result=result)


class Score(Resource):
    def get(self, id):
        q = db.session.query
        result = q(models.Score).get(id)
        result = ScoreSerializer(result).data
        return jsonify(result=result)

    def put(self, id):
        pass

    def delete(self, id):
        pass


class Scores(Resource):
    def get(self):
        q = db.session.query
        result = q(models.Score).all()
        result = [ScoreSerializer(r).data for r in result]
        return jsonify(result=result)


class Tag(Resource):
    def get(self, id):
        q = db.session.query
        result = q(models.Tag).get(id)
        result = TagSerializer(result).data
        return jsonify(result=result)

    def put(self, id):
        pass

    def delete(self, id):
        pass


class Tags(Resource):
    def get(self):
        q = db.session.query
        result = q(models.Tag).all()
        result = [TagSerializer(r).data for r in result]
        return jsonify(result=result)



'''
#!flask/bin/python

"""Alternative version of the ToDo RESTful server implemented using the
Flask-RESTful extension."""

from flask import Flask, jsonify, abort, request, make_response, url_for
from flask.views import MethodView
from flask.ext.restful import Api, Resource, reqparse, fields, marshal
from flask.ext.httpauth import HTTPBasicAuth

app = Flask(__name__, static_url_path = "")
api = Api(app)
auth = HTTPBasicAuth()

@auth.get_password
def get_password(username):
    if username == 'miguel':
        return 'python'<commit_msg>no need for jsonify. Flask-restful takes care of that<commit_after>from flask.ext.restful import Resource
from serializers import ActivitySerializer, ScoreSerializer, TagSerializer, \
    UserSerializer
import models


# Will be set by api.create_app()
db = None


class User(Resource):
    def get(self, id):
        q = db.session.query
        result = q(models.User).get(id)
        result = UserSerializer(result).data
        return {'result': result}

    def put(self, id):
        pass

    def delete(self, id):
        pass


class Activity(Resource):
    def get(self, id):
        q = db.session.query
        result = q(models.Activity).get(id)
        result = ActivitySerializer(result).data
        return {'result': result}

    def put(self, id):
        pass

    def delete(self, id):
        pass


class Activities(Resource):
    def get(self):
        q = db.session.query
        result = q(models.Activity).all()
        result = [ActivitySerializer(r).data for r in result]
        return {'result': result}


class Score(Resource):
    def get(self, id):
        q = db.session.query
        result = q(models.Score).get(id)
        result = ScoreSerializer(result).data
        return {'result': result}

    def put(self, id):
        pass

    def delete(self, id):
        pass


class Scores(Resource):
    def get(self):
        q = db.session.query
        result = q(models.Score).all()
        result = [ScoreSerializer(r).data for r in result]
        return {'result': result}


class Tag(Resource):
    def get(self, id):
        q = db.session.query
        result = q(models.Tag).get(id)
        result = TagSerializer(result).data
        return {'result': result}

    def put(self, id):
        pass

    def delete(self, id):
        pass


class Tags(Resource):
    def get(self):
        q = db.session.query
        result = q(models.Tag).all()
        result = [TagSerializer(r).data for r in result]
        return {'result': result}



'''
#!flask/bin/python

"""Alternative version of the ToDo RESTful server implemented using the
Flask-RESTful extension."""

from flask import Flask, jsonify, abort, request, make_response, url_for
from flask.views import MethodView
from flask.ext.restful import Api, Resource, reqparse, fields, marshal
from flask.ext.httpauth import HTTPBasicAuth

app = Flask(__name__, static_url_path = "")
api = Api(app)
auth = HTTPBasicAuth()

@auth.get_password
def get_password(username):
    if username == 'miguel':
        return 'python'
{'fraction_non_alphanumeric': 0.11040759794222398, 'fraction_numerical': 0.0, 'mean_word_length': 2.6630434782608696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3048674', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1476, 'n_words': 428}