Exemplo n.º 1
0
 def edit_entry(user_id, breakfast, lunch, dinner, snacks, restaurant,
                entry_date):
     command = 'UPDATE blog \
                 SET breakfast =  "{}", lunch = "{}", dinner = "{}", snacks = "{}", restaurant = "{}" \
                 WHERE user_id = {} AND entry_date = "{}"'.format(
         breakfast, lunch, dinner, snacks, restaurant, user_id, entry_date)
     execute(command)
Exemplo n.º 2
0
 def get_user(username):
     command = 'SELECT id from user WHERE username = "******"'.format(username)
     data = execute(command).fetchall()
     if len(data) == 0: # if no user exists with the username then return None
         return None
     else:
         return User(data[0][0]) #returns user oobject
Exemplo n.º 3
0
 def __init__(self, id, date=None):
     if (date):
         command = 'SELECT * FROM blog WHERE user_id={} AND entry_date="{}"'.format(
             id, date)
     else:
         command = 'SELECT * FROM blog WHERE user_id={} ORDER BY entry_date DESC'.format(
             id)
     data = execute(command).fetchall()
     self.id = id
     self.data = data
     self.user = User(id)
Exemplo n.º 4
0
 def check_date_taken(user_id, entry_date):
     command = 'SELECT * FROM blog WHERE user_id=%s AND entry_date="%s"' % (
         user_id, entry_date)
     data = execute(command).fetchall()
     return len(data) > 0
Exemplo n.º 5
0
 def add_entry(user_id, breakfast, lunch, dinner, snacks, restaurant,
               entry_date):
     command = 'INSERT INTO blog (user_id, breakfast, lunch, dinner, snacks, restaurant, entry_date) \
         VALUES ({}, "{}", "{}", "{}", "{}", "{}", "{}")'.format(
         user_id, breakfast, lunch, dinner, snacks, restaurant, entry_date)
     execute(command)
Exemplo n.º 6
0
 def __init__(self, id):
     command = 'SELECT * FROM user WHERE id={}'.format(id)
     data = execute(command).fetchall()
     self.id = int(data[0][0])
     self.username = str(data[0][1])
     self.password = str(data[0][2])
Exemplo n.º 7
0
 def new_user(username, password):
     command = 'INSERT INTO user (username, password) VALUES ("{}", "{}")'.format(username, password)
     execute(command)
Exemplo n.º 8
0
 def username_avaliable(username):
     command = 'SELECT id FROM user WHERE username = "******"'.format(username)
     data = execute(command).fetchall()
     return len(data) == 0