From fdf6166100adecca1ba848360b58f9166c05902a Mon Sep 17 00:00:00 2001 From: pbr4nzfkh <18879212807@163.com> Date: Sun, 17 Mar 2024 16:13:55 +0800 Subject: [PATCH] =?UTF-8?q?Delete=20'=E5=9F=BA=E6=9C=AC=E7=BB=93=E6=9E=84/?= =?UTF-8?q?042=20restful/tf-35-app.py'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 基本结构/042 restful/tf-35-app.py | 62 --------------------------- 1 file changed, 62 deletions(-) delete mode 100644 基本结构/042 restful/tf-35-app.py diff --git a/基本结构/042 restful/tf-35-app.py b/基本结构/042 restful/tf-35-app.py deleted file mode 100644 index 7bbf6f8..0000000 --- a/基本结构/042 restful/tf-35-app.py +++ /dev/null @@ -1,62 +0,0 @@ -# -*- coding: utf-8 -*- -from flask import Flask, request, jsonify, abort -from functools import lru_cache -from cppy.cp_util import * - -app = Flask(__name__) - -# 模拟数据库 -books_db = [] - -# 用于缓存用户数据库的装饰器 -@lru_cache(maxsize=None) -def get_books_db(): - return books_db - -#查询所有资源 -@app.route('/books', methods=['GET']) -def get_books(): - return jsonify(get_books_db()) - -#查询某个资源 -@app.route('/books/', methods=['GET']) -def get_book(book_id): - book = next((book for book in get_books_db() if book['id'] == book_id), None) - if book is None: - abort(404) - return jsonify(book['content']) - - -# 创建或更新新资源 -@app.route('/books/', methods=['PUT']) -def update_book(book_id): - global books_db - book_to_update = request.json - print(book_to_update) - books_db = get_books_db() - - book = next((book for book in books_db if book['id'] == book_id), None) - - if book is None: - books_db.append(book_to_update) - else: - book.update(book_to_update) - - return jsonify(books_db), 200 - -#操作一个资源 -@app.route('/books//word_frequency', methods=['GET']) -def word_frequency(book_id): - global books_db - book = next((book for book in get_books_db() if book['id'] == book_id), None) - filepath = book['content'] - word_list = extract_file_words(filepath) - word_frequency = get_frequencies(word_list) - word_frequency = sort_dict(word_frequency) - print_word_freqs(word_frequency) - # return jsonify({'message': f'User {book_id} deleted'}), 200 - return jsonify(word_frequency), 200 - -if __name__ == '__main__': - app.run(debug=True) -