From 2502d9c7f4e3aa6427f7474761087658cff9d4d7 Mon Sep 17 00:00:00 2001 From: Corder Guy Date: Tue, 17 Apr 2018 15:40:51 -0500 Subject: [PATCH] Improve PEP8 compliance --- mocha_server.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/mocha_server.py b/mocha_server.py index 4f2a2b8..7f0283b 100755 --- a/mocha_server.py +++ b/mocha_server.py @@ -2,6 +2,7 @@ ''' Handle API requests to the database ''' + import json import sqlite3 from os import path @@ -13,11 +14,12 @@ 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 fetch_users(user_ids): ''' - Gets a list of users searching by name. - This can also easily be done by user_id. - ''' + Gets a list of users searching by name. + This can also easily be done by user_id. + ''' conn = sqlite3.connect(DATABASE) conn.row_factory = sqlite3.Row cursor = conn.cursor() @@ -39,9 +41,12 @@ def fetch_users(user_ids): def get_top_n(search_parameter, desc, num): ''' In progress. - Currently the query seems to work, but returning a dict does not preserve order. + Currently the query seems to work, but returning a dict does not + preserve order. - Store an orderd id list and put that in the json? + Store an orderd id list and put that in the json? + + Alternatively, sort on the client-side. ''' conn = sqlite3.connect(DATABASE) conn.row_factory = sqlite3.Row @@ -54,7 +59,7 @@ def get_top_n(search_parameter, desc, num): (search_parameter, num)) output = cursor.fetchall() - #print(output) + # print(output) output = json.dumps([dict(row) for row in output]) conn.commit() @@ -78,7 +83,10 @@ def update_row(_user_id, _updated_username): def insert_row(user_id, username): ''' Inserts a row for a NEW user with given parameters - This may work better with AUTOINCREMENT to avoid arbitrary ids and duplicates + This may work better with AUTOINCREMENT to avoid arbitrary ids and + duplicates. + + Alternatively, use randomized unique IDs. ''' conn = sqlite3.connect(DATABASE)