Add fetch_users
This commit is contained in:
parent
3230aba345
commit
fd7e3a0628
1 changed files with 9 additions and 5 deletions
|
@ -13,7 +13,7 @@ if not path.exists(DATABASE):
|
|||
# TODO: Add fetching of top N users by score
|
||||
# TODO: Add ability to store and retrieve avatars (as image files?)
|
||||
|
||||
def get_users(username_list):
|
||||
def fetch_users(user_ids):
|
||||
'''
|
||||
Gets a list of users searching by name.
|
||||
This can also easily be done by user_id.
|
||||
|
@ -22,8 +22,8 @@ def get_users(username_list):
|
|||
conn.row_factory = sqlite3.Row
|
||||
cursor = conn.cursor()
|
||||
output = []
|
||||
for usr in username_list:
|
||||
cursor.execute('select * from users where username=(?)', (usr, ))
|
||||
for user_id in user_ids:
|
||||
cursor.execute('select * from users where user_id=(?)', (user_id, ))
|
||||
output += cursor.fetchall()
|
||||
|
||||
output = json.dumps([dict(row) for row in output])
|
||||
|
@ -136,7 +136,10 @@ def process_request(uri):
|
|||
if len(parts) < 2:
|
||||
output = None
|
||||
elif parts[1] == 'users' and len(parts) > 2:
|
||||
output = fetch_user(parts[2])
|
||||
if ',' in parts[2]:
|
||||
output = fetch_users(parts[2].split(','))
|
||||
else:
|
||||
output = fetch_user(parts[2])
|
||||
elif parts[1] == 'top' and len(parts) > 2:
|
||||
output = fetch_top_n(parts[2])
|
||||
else:
|
||||
|
@ -165,9 +168,10 @@ def application(environ, start_response):
|
|||
|
||||
return [output]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
USERNAMES = ['andrew', 'Corder']
|
||||
print(get_users(USERNAMES))
|
||||
print(fetch_users(USERNAMES))
|
||||
|
||||
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
|
||||
|
|
Reference in a new issue