Пример #1
0
 def saveUserData(self):
     mydb = s3DB.s3DB('users')
     mydb.bucket = "tbos-data"
     mydb.index = "user_id"
     user = dict(self.toJSON())
     user.pop('entries')
     mydb.save(user)
Пример #2
0
 def load(self, user_id, year):
     mydb = s3DB.s3DB('entries')
     mydb.bucket = "tbos-data"
     all_entries = mydb.load(year)
     user_entries = {
         "1": [],
         "2": [],
         "3": [],
         "4": [],
         "5": [],
         "6": [],
         "7": []
     }
     if all_entries:
         if all_entries['months']:
             for month in all_entries['months']:
                 current_month = month['month']
                 for day in month['days']:
                     current_day = day['day']
                     for entry in day['entries']:
                         if entry['user_id'] == user_id:
                             user_entries[entry['type']].append(
                                 date(year, current_month,
                                      current_day).strftime("%Y-%m-%d"))
     return user_entries
Пример #3
0
def add_user():
    user = request.get_json()
    mydb = s3DB.s3DB('users')
    mydb.bucket = "tbos-data"
    mydb.index = "principalID"
    #user = {"name": "Dan Danciu", "age": 23}
    mydb.save(user)
    return jsonify({"message": "User added."}), 200
Пример #4
0
def delete_user():
    user = request.get_json()
    mydb = s3DB.s3DB('users')
    mydb.bucket = "tbos-data"
    if 'name' in user:
        if mydb.delete(user["name"]):
            return jsonify(f"User {user['name']} deleted" ), 200
    else:
        return jsonify("User name not specified"), 404
Пример #5
0
 def save(self, user_id, year):
     mydb = s3DB.s3DB('entries')
     mydb.bucket = "tbos-data"
     mydb.index = "year"
     data = mydb.load(year)
     if data:
         data[user_id] = self.toJSON()
     else:
         data = {'year': year, 'months': []}
     mydb.save(data)
Пример #6
0
 def load(self, user_id):
     mydb = s3DB.s3DB('users')
     mydb.bucket = "tbos-data"
     user = mydb.load(user_id)
     return user
Пример #7
0
 def save(self):
     mydb = s3DB.s3DB('all_users')
     mydb.bucket = "tbos-data"
     mydb.index = 'index'
     mydb.save(self.toJSON())
Пример #8
0
 def load(self):
     mydb = s3DB.s3DB('all_users')
     mydb.bucket = "tbos-data"
     user_list = mydb.load('all_users')
     return user_list
Пример #9
0
 def load(self, year):
     mydb = s3DB.s3DB('entries')
     mydb.bucket = "tbos-data"
     entries = mydb.load(year)
     return entries