def add_transaction(): json=request.getjson() transaction_key=['sender','receiver','amount'] if not all(key in json for key in transaction_key): return 'Some elements of the transaction are missing', 400 index = blockchain.add_transaction(json['sender'], json['receiver'], json['amount']) response = {'message': f'This transaction will be added to Block {index}'} return jsonify(response), 201
def post(self): data = request.getjson() new_topic = Topic.objects.get(topic_id='Social') new_question = Question(topic=new_topic, string=data['string'], username=data['username'], views=data['views']) new_question.save()
def add_nodes(): json=request.getjson() nodes=json.get('nodes') if nodes== None: return "NO NODDDESSSS",400 for node in nodes: blockchain.add_node(node) response={'msg':"all the nodes are added successfully", 'nodes':list(blockchain.nodes)} return jsonify(response),201
def send_transaction(): json = request.getjson() transaction_key = [ 'sender', 'receiver', 'amount', 'utxo_block_index', 'utxo_transaction_index' ] if not all(key in json for key in transaction_key): return 'Some elements of the transaction are missing', 400 blockchain.add_transactions_to_mempol(json['sender'], json['reciver'], json['amount'], json['utxo_block_index'], json['utxo_transaction_index']) response = {'msg': "added"} return jsonify(response), 200
def put_user(user_id=None): ''' Update a user object ''' obj_users = storage.get('User', user_id) if obj_user is None: abort(404) if not request.json: return jsonify({"error": "Not a JSON"}), 400 for key, value in request.getjson(): if key not in ['id', 'created_at', 'email', 'updated_at']: setattr(obj_user, key, value) obj_user.save() return (jsonify(obj_user.to_dict()), 200)
def put_review(review_id): ''' Update a review object ''' obj_review = storage.get('Review', review_id) if obj_review is None: abort(404) if not request.json: return jsonify({"error": "Not a JSON"}), 400 for key, value in request.getjson(): if key not in ['id', 'created_at', 'user_id', 'updated_at']: setattr(obj_user, key, value) obj_review.save() return (jsonify(obj_review.to_dict()), 200)
def updatefriends(): r=request.getjson() for i in r['entry']: if 'friends' in i['changed_fields']: user=models.User.query.filter_by(fbid=i['uid']) r=requests.get('https://graph.facebook.com/me/friends?access_token='+user.token) for i in r.json()['data']: friendid=i['id'] friend=models.User.query.filter_by(fbid=friendid).first() if (friend!=None): newfriend1=models.Friends(userid=user.id,friendid=friend.id) newfriend2=models.Friends(userid=friend.id,friendid=user.id) db.session.add(newfriend1) db.session.add(newfriend2) db.session.commit() return 'Updated!'
def request_loader(request): username = request.getjson()
class Detect(Resource): def post(self): postedData=request.getjson()