Exemplo n.º 1
0
from flask import jsonify, request, Flask
from flask_restx import Resource, Namespace, fields
from app.main.service.processos_service import ProcessoService
from app.main.bd.repository import environment_config, init_bd

api = Namespace(
    'Populando banco',
    "Endpoint para popular o banco. Usada apenas para desenvolvimento.")

service = ProcessoService()

cfg = environment_config()


@api.route("")
class PopulandoBanco(Resource):
    def get(self):
        chave = request.args.get("chave", "", str)
        if chave == cfg["chave_populando"]:
            service.update_processos()
        else:
            return jsonify({
                'response': {
                    'code': '401',
                    'message': 'Chave incorreta.',
                    'body': None
                }
            })
 def __init__(self):
     cfg = repository.environment_config()
     self.connection = psycopg2.connect(cfg["database_url"],
                                        sslmode=cfg["sslmode"])
     self.cursor = self.connection.cursor()