Example #1
0
                resp.status_code = 500
            
            return resp 

class GetPeople(Resource):
    def get(self,id):
        if request.method == 'GET':
            try:
                user = PersonModel.find_by_id(id)
                if user:
                    resp = jsonify(person=user.json())
                    resp.status_code = 200
                else:
                    resp = jsonify(message='No se encontrĂ³ persona con ese id!')
                    resp.status_code = 404
            except ValueError as e:
                resp = jsonify(message='Error, {}'.format(e))
                resp.status_code = 500

            return resp

##
## Actually setup the Api resource routing here
##
api.add_resource(ServiceBirthday, '/birthday')
api.add_resource(AllPeople,'/get-people')
api.add_resource(GetPeople,'/get-people-id/<string:id>')

if __name__ == "__main__":
    create_database('{}/db/database_file.db'.format(base_dir))
    app.run(debug=True,host='127.0.0.1')
Example #2
0
def handle_500_error(_error):
    """Return a http 500 error to client"""
    return make_response(jsonify({'error': 'Server error'}), 500)


@app.route("/")
def index():
    return "API Working"


if __name__ == '__main__':

    PARSER = argparse.ArgumentParser(description="Api FakePost Insta")

    PARSER.add_argument(
        '--debug',
        action='store_true',
        help="Use flask debug/dev mode with file change reloading")
    ARGS = PARSER.parse_args()

    PORT = int(os.environ.get('PORT', 5000))

    if ARGS.debug:
        print("Running in debug mode")
        create_database('./db/data.db')
        CORS = CORS(app)
        app.run(host='0.0.0.0', port=PORT, debug=True)
    else:
        # create_database('./db/data.db')
        app.run(host='0.0.0.0', port=PORT, debug=False)
Example #3
0
from flask import Flask, jsonify
from flask_restful import Api

from resources.message import Message, MessageList, MessageRegister

from db.database import create_database



app = Flask(__name__)
api = Api(app)



api.add_resource(Message, '/message/<string:id>')
api.add_resource(MessageList, '/messages')
api.add_resource(MessageRegister, '/message/add')



if __name__ == '__main__':
    create_database('./db/datamessage.db')
    app.run()
Example #4
0
from flask import Flask, jsonify
from flask_restful import Api
from resources.forecast import Forecast, ForecastAnalyze
from db.database import create_database
from flask_sqlalchemy import SQLAlchemy
from config import app, api, db, db_rel_path

api.add_resource(Forecast, '/cidade')
api.add_resource(ForecastAnalyze, '/analise')

if __name__ == '__main__':
    #db.create_all()
    create_database(db_rel_path)
    app.run()
Example #5
0
from db.database import create_database

create_database('./db/datashop.db')
Example #6
0
 def setUpClass(cls):
     if os.path.exists('../db/data.db'):
         # os.system('rm ../db/data.db')
         os.remove('../db/data.db')
     create_database('../db/data.db')
     cls.uri = 'http://127.0.0.1:5000'
 def setUp(self):
     if os.path.exists('./db/data.db'):
         # os.system('rm ../db/data.db')
         os.remove('./db/data.db')
     create_database('./db/data.db')