diff --git a/app.py b/app.py index 4185675..89fb40d 100644 --- a/app.py +++ b/app.py @@ -38,5 +38,15 @@ def register(): return make_response(json.dumps({'result': 'fail'})) +@app.route('/get_list', methods=['POST']) +def get_list(): + cookie_jwt = request.cookies.get('jwt') + if cookie_jwt is not None: + sports_list = dao.get_list() + return make_response(json.dumps({'result': 'success', 'list': sports_list})) + else: + return make_response(json.dumps({'result': 'fail'})) + + if __name__ == '__main__': app.run() diff --git a/dao.py b/dao.py index 576262e..5690125 100644 --- a/dao.py +++ b/dao.py @@ -14,6 +14,35 @@ def valid(username, password): return True +def get_list(): + sports_list = [{'type': '男子', 'list': []}, + {'type': '女子', 'list': []}, + {'type': '团体', 'list': []}] + sports_types = {'男子': ['100', '200', '400', '800', '1500', '跳高', '跳远', '三级跳', '铅球'], + '女子': ['100', '200', '400', '800', '跳高', '跳远', '三级跳', '铅球'], + '团体': ['男子4*100', '女子4*100', '男子引体向上', '女子仰卧起坐', '长绳']} + transistor = {'男子': 0, '女子': 1, '团体': 2} + db_connection = sqlite3.connect('sports-registration.sqlite') + base_cursor = db_connection.cursor() + for sports_type in sports_types: + for sports_name in sports_types[sports_type]: + type_cursor = base_cursor.execute(f'SELECT username FROM list ' + f'WHERE program_type="{sports_type}" ' + f'AND program_name="{sports_name}";') + current_list = type_cursor.fetchall() + if current_list == []: + sports_list[transistor[sports_type]]['list'].extend([[sports_name, '暂无']]) + else: + head_list = [i for i in range(len(current_list))] + head_list[0] = sports_name + for i in range(len(head_list) - 1): + head_list[i + 1] = '' + sports_list[transistor[sports_type]]['list'].extend([list(line) for line in + zip(head_list, + [name[0] for name in current_list])]) + return sports_list + + def register(username, program_type, program_name): db_connection = sqlite3.connect('sports-registration.sqlite') base_cursor = db_connection.cursor()