Esempio n. 1
0
def userlist():
    if request.method == 'get':
        return users
    if request.method == 'delete':
        age = request.args.get('age')
        name = request.args.get('name')
        with open('/tmp/data.txt', 'r') as f:
            data = f.read()
            records = JSONTag.loads(data, age)
            for record in records:
                if record['name'] == name:
                    return jsonify(record)
            return jsonify({'error': 'data not found'})
    if request.method == 'post':

        def update_record():
            record = json.loads(request.data)
            new_records = []
            with open('/tmp/data.txt', 'r') as f:
                data = f.read()
                records = json.loads(data)
            for r in records:
                if r['name'] == record['name']:
                    r['email'] = record['email']
                new_records.append(r)
            with open('/tmp/data.txt', 'w') as f:
                f.write(json.dumps(new_records, indent=2))
            return jsonify(record)
Esempio n. 2
0
 def get(self, user_id):
     name = request.args.get('name')
     age = request.args.get('age')
     with open('/tmp/data.txt', 'r') as f:
         data = f.read()
         records = JSONTag.loads(data)
         for record in records:
             if record['name'] == name:
                 return jsonify(record)
         return jsonify({'error': 'data not found'})