def get_all_available_requests(): usermail = request.args.get("usermail") today_date = datetime.now().date().isoformat() error_response = {"status": "fail", "message": "Request not found"} available_requests = [ request.to_json() for request in Request.query.filter( Request.lender == None, Request.requester != usermail, Request.enddate >= today_date, ).all() ] if not available_requests: return jsonify(error_response), 404 response = { "status": "success", "data": { "available requests": get_category_name(available_requests) }, } return jsonify(response), 200
def new_card(): card = Cards.from_json(request.to_json()) card.owner = g.current_user db.session.add(card) db.session.commit() return jsonify(card.to_dict(), 201, {'Location': url_for('api.get_card', id=card.id)})
def request_answer(resp, idRequest, requestAnswer): user = resp['data'] request = RequestRideModel.find_by_id(idRequest) print(request.to_json(), flush=True) if request is None: return jsonify(createFailMessage(None)), 404 if request.requestStatus != "P": return jsonify("Essa solicitação já foi respondida."), 400 ride = RideModel.find_by_id(request.idRide) if ride.idUser != user['idUser']: return jsonify(createFailMessage(None)), 400 try: response = ResponseRideModel(request.idRequest, request.idPassenger, "P") if requestAnswer == "1": setattr(request, 'requestStatus', "A") response.answer = "A" else: setattr(request, 'requestStatus', "R") response.answer = "R" response.save_to_db() response_object = createSuccessMessage('Requisição respondida com sucesso.') return jsonify(response_object), 200 except Exception as e: db.session.rollback() return jsonify(createFailMessage(e)), 503
def get_a_message(message_id): if 'credentials' not in session: session['scope'] = 'readonly' return redirect('authorize') credentials = Credentials(**session['credentials']) try: service = build('gmail', 'v1', credentials=credentials) except HttpError as error: app.logger.error('An error occured: {:s}'.format(error)) return 'An error occured: {:s}'.format(error) try: request = service.users().messages().get(userId='me', id=message_id, format='full') app.logger.info(request.to_json()) result = service.users().messages().get(userId='me', id=message_id, format='full').execute() except HttpError as error: app.logger.error('An error occured: {:s}'.format(error)) return 'An error occured: {:s}'.format(error) return jsonify(result)
def get_requests_filtered_by_category(productcategoryid): usermail = request.args.get("usermail") today_date = datetime.now().date().isoformat() error_response = {"status": "fail", "message": "Request not found"} requests = get_category_name([ request.to_json() for request in Request.query.filter( Request.lender == None, Request.requester != usermail, Request.enddate >= today_date, Request.productcategoryid == productcategoryid, ).all() ]) if not requests: return jsonify(error_response), 404 response = { "status": "success", "data": { "requests": requests }, } return jsonify(response), 200
def process_post(): headers = request.headers resp = Response(status=200, mimetype='application/json') for k, v in headers.items(): if v not in hks_true: return resp else: message = request.to_json() return resp
def changePassword(): # email = request.args.get('email') # # password = md(data['password']) # password = request.args.get('password') data = request.to_json('email') email = data['email'] # password = md(data['password']) password = data['password'] User.query.filter_by(email=email).update({"password": password}) db.session.commit() return Success()
def get_all_request(): requester = request.args.get("requester") lender = request.args.get("lender") if requester: requests = get_category_name([ request.to_json() for request in Request.query.filter_by(requester=requester) ]) response = { "status": "success", "data": { "requests": requests }, } return jsonify(response), 200 elif lender: requests = get_category_name([ request.to_json() for request in Request.query.filter_by(lender=lender) ]) response = { "status": "success", "data": { "requests": requests }, } return jsonify(response), 200 requests = get_category_name([ request.to_json() for request in Request.query.filter_by(lender=None) ]) response = { "status": "success", "data": { "requests": requests }, } return jsonify(response), 200
def update_states(state_id): """ Updates State objects """ states_storage = storage.get('State', state_id) if not states_storage: abort(404) dict_request = request.to_json() if "name" not in dict_request.keys(): abort(400, {"error": "Not a JSON"}) states_storage = states_storage.to_json() keys = ['id', 'created_at', 'updated_at'] states_storage.update({key: value for (key, value) in dict_request.items() if key not in keys}) storage.save() return (jsonify(states_storage), 200)
def login(): request.to_json() content = request.get_json() print(type(content)) params = { 'username': request.get_json('u'), 'password': request.get_json('p'), 'authback': request.get_json('a') } return content json = str("username="******"@pam&password=" + pswd) loginurl = proxmoxurl + 'json/access/ticket' r = requests.post(loginurl, data=json) if r.json()['data'] == None: return error() else: authtoken = r.json()['data']['ticket'] csrf = r.json()['data']['CSRFPreventionToken'] session['authtoken'] = authtoken session['csrf'] = csrf return 'You have been logged in!'
def transaction_data(): try: client = MongoClient( 'mongodb://*****:*****@hackwestern-shard-00-00-4qcqm.gcp.mongodb.net:27017,hackwestern-shard-00-01-4qcqm.gcp.mongodb.net:27017,hackwestern-shard-00-02-4qcqm.gcp.mongodb.net:27017/test?ssl=true&replicaSet=hackWestern-shard-0&authSource=admin' ) db = client['Dolphin'] collection = db['Users'] except: return 'error connecting to mongo!' finally: client.close() for i in request.to_json(): collection.update_one({'wallet_id': i['wallet_id']}, { "$push": { "balance": i['balance'], "date": i['date'], "amount": i['amount'], "wallet_id": i['wallet_id'] } }) return "sucess!"
def add_vendor(): request_body = request.to_json() vendor = VendorModel(**request_body).save() return {"message": f"Vendor added with an ID of {vendor.id}"}, 200
def log_exception(self, exc_info): # pylint: disable=no-member self.logger.error( 'ERROR Request INFO: {}'.format(request.to_json(pretty=True)), exc_info=exc_info, extra=request.to_dict())
def get_company(id): request = Company.query.filter_by(id=id).first() if request is None: abort(404) return jsonify(request.to_json(list_view=True))
def get_game(id): request = Game.query.filter_by(id=id).first() if request is None: abort(404) return jsonify(request.to_json())
def get_game(id): request = Game.query.filter_by(id=id).first() if request is None: abort(404) return jsonify(request.to_json())
def get_company(id): request = Company.query.filter_by(id=id).first() if request is None: abort(404) return jsonify(request.to_json(list_view=True))