Add avatar column and getter/setter
This commit is contained in:
parent
23b48ec7fc
commit
ef8c86710b
2 changed files with 34 additions and 5 deletions
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
|
@ -161,6 +161,37 @@ def update(user_id, score):
|
||||||
return '[]'
|
return '[]'
|
||||||
|
|
||||||
|
|
||||||
|
def set_avatar(user_id, new_avatar):
|
||||||
|
conn = sqlite3.connect(DATABASE)
|
||||||
|
conn.row_factory = sqlite3.Row
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('UPDATE users SET avatar = (?) WHERE user_id = (?)',
|
||||||
|
(new_avatar, user_id))
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
return '[]'
|
||||||
|
|
||||||
|
|
||||||
|
def get_avatar(user_id):
|
||||||
|
conn = sqlite3.connect(DATABASE)
|
||||||
|
conn.row_factory = sqlite3.Row
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute(
|
||||||
|
'SELECT avatar FROM users WHERE user_id = (?)',
|
||||||
|
(user_id))
|
||||||
|
|
||||||
|
output = cursor.fetchall()
|
||||||
|
output = json.dumps([dict(row) for row in output])
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
if output == '[]':
|
||||||
|
output = None
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
def process_request(uri):
|
def process_request(uri):
|
||||||
'''
|
'''
|
||||||
Handles the API endpoint.
|
Handles the API endpoint.
|
||||||
|
@ -215,10 +246,8 @@ def application(environ, start_response):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
new_score = random.randint(1, 100)
|
print(get_avatar('1'))
|
||||||
print(fetch_user(1))
|
set_avatar('1', 'newavatar')
|
||||||
print(new_score)
|
print(get_avatar('1'))
|
||||||
update(1, new_score)
|
|
||||||
print(fetch_user(1))
|
|
||||||
|
|
||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
|
||||||
|
|
Reference in a new issue