Order user responses by score
This commit is contained in:
parent
dca83215aa
commit
10a13f74e6
1 changed files with 5 additions and 4 deletions
|
@ -72,9 +72,11 @@ def fetch_user(user_id):
|
||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
if user_id != '*': # must use (?), (item,) format
|
if user_id != '*': # must use (?), (item,) format
|
||||||
cursor.execute('SELECT * FROM users WHERE user_id=(?)', (user_id, ))
|
cursor.execute(
|
||||||
|
'SELECT * FROM users WHERE user_id=(?) ORDER BY score DESC',
|
||||||
|
(user_id, ))
|
||||||
else:
|
else:
|
||||||
cursor.execute('SELECT * FROM users')
|
cursor.execute('SELECT * FROM users ORDER BY score DESC')
|
||||||
|
|
||||||
output = cursor.fetchall()
|
output = cursor.fetchall()
|
||||||
output = json.dumps([dict(row) for row in output])
|
output = json.dumps([dict(row) for row in output])
|
||||||
|
@ -155,7 +157,6 @@ def application(environ, start_response):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(fetch_top_n(3))
|
print(fetch_user('*'))
|
||||||
|
|
||||||
|
|
||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
|
||||||
|
|
Reference in a new issue