def estabelecimento(): estabelecimento = [] collection = connect() for query in collection['estabelecimento'].find({}): estabelecimento.append({ 'nome': query["nome"], 'telefone': query["telefone"], 'perfil_origem': query["perfil_origem"], 'perfil_movimento': query["perfil_movimento"], 'perfil_tipo': query["perfil_tipo"], 'latitude': query["latitude"], 'longitude': query["longitude"], 'endereco': query["endereco"], 'cnpj': query["cnpj"], 'consumidores_visitados': query["consumidores_visitados"], 'google_rating': query["google_rating"], 'google_rating_total': query["google_rating_total"], 'regra_fumante': query["regra_fumante"], 'level_preco': query["level_preco"], 'qrcode_token': query["qrcode_token"], 'vendas': query["vendas"], 'create_at': query["create_at"], 'modified_at': query["modified_at"], 'lista_consumidores': str(query["lista_consumidores"]), 'itens_vendidos': str(query["itens_vendidos"]), 'cupom': query["cupom"], 'estoque': query["estoque"] }) return jsonify({'estabelecimento': estabelecimento})
def pagamento(): pagamentos = [] collection = connect() for query in collection['pagamento'].find({}): pagamentos.append({ 'cliente': query['cliente'], 'estabelecimento': query['estabelecimento'], 'valor': query['valor'], 'status': query['status'], 'modo': query['modo'], 'voucher': query['voucher'], 'create_at': query['create_at'], 'modified_at': query['modified_at'] }) return jsonify({'pagamentos': pagamentos})
def put(self): '''Update a classroom''' db = connect() classroom = request.json["classroom"] # students = request.json["students"]) group = request.json["group"] for n in students: if not str(n).startswith(classroom): return abort( 406, "Student doesn't belong to classroom: student ID must start with classroom ID" ) # for n in db.students.find({"classroom":classroom}): # db.students.update({"_id":n["_id"]} {"$set":{"group": group, "classroom": classroom}}) return { "message": "Sucessfully udpated classroom {}".format(classroom) }, 204
def post(self): '''Add a new classroom''' db = connect() classroom = request.json["classroom"] students = request.json["students"] group = request.json["group"] for n in students: if not str(n).startswith(classroom): return { "message": "Student doesn't belong to classroom: student ID must start with classroom ID" }, 406 else: pass # db.students.update({"student":n, "group": group, "classroom": classroom},True) return { "message": "Sucessfully added classroom {}".format(classroom) }, 204
def update(): try: settings.refresh() settings.connection = settings.connect() except Exception as e: print(e) settings.default_settings() settings.refresh() try: if not settings.connection == False: fb.version_control() if fb.status == "update": print("An update have done") elif fb.status == "major": print("MAJOR UPDATE NEEDED") else: print("PLEASE CONNECT TO INTERNET TO CHECK FOR UPDATES") except Exception as e: print("Update failed, ERROR : ", errorlog(e))
def consumidor(): consumidor = [] collection = connect() for query in collection['consumidor'].find({}): consumidor.append({ "nome": query["nome"], "telefone" : query["telefone"], "gostos_origem" : query['gostos_origem'], "gosto_movimentacao" : query['gosto_movimentacao'], "gosto_tipo" : query['gosto_tipo'], "estabelecimento_visitados" : query['estabelecimento_visitados'], "fumante" : query['fumante'], "renda" : query['renda'], "alcoolismo" : query['alcoolismo'], "create_at" : query['create_at'], "modified_at" : query['modified_at'] }) return jsonify({'consumidor': consumidor})
def get(self): """ Classroom definition ### Description Expose the table `students` grouped by classroom created at initialization of the database: by the document list and updated throught a CSV referenced file that add group information Group define if we include the student into stats ### Output example: ```json ``` ## Documentation Consult [documentation](http://doc.ludoeducation.fr/researcher-guide/stats/students/) """ db = connect() classroom = list(db.students.find({"classroom": classroom})) if len(classroom) == 0: return {"message": "Classroom {} Not Found".format(classroom)}, 404 groups = set([n["group"] for n in classrom]) if len(groups) != 1: return { "message": "Classroom has multiple groups {}. Aborting".format(groups) }, 409 return { "classroom": classroom, "group": groups[0], "students": [n["student"] for n in classroom] }
from flask import request from flask_restx import Namespace, Resource, abort, fields from settings import connect, errors, db, TOKEN from functools import wraps from utils.db import connect db = connect() def token_required(f): @wraps(f) def decorated(*args, **kwargs): token = None if 'X-API-KEY' in request.headers: token = request.headers["X-API-KEY"] if not token: return {"message": "Token is missing."}, 401 if token != TOKEN: return {"message": "Invalid Token"}, 401 return f(*args, **kwargs) return decorated ns_student = Namespace('students', description='Consult and update students in the game') student_definition = ns_student.model( 'Student', { 'student': fields.Integer(required=True, example=212,