From 1c13043083db6a11e2a4ec01ff2a633ba8526026 Mon Sep 17 00:00:00 2001 From: jiulinxiri Date: Thu, 31 Oct 2024 09:25:08 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/flaskAPI.iml | 21 +++ .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 149 ++++++++++++++++++ Dockerfile | 12 ++ app.py | 136 ++++++++++++++++ requirements.txt | 9 ++ 9 files changed, 354 insertions(+) create mode 100644 .idea/flaskAPI.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 Dockerfile create mode 100644 app.py create mode 100644 requirements.txt diff --git a/.idea/flaskAPI.iml b/.idea/flaskAPI.iml new file mode 100644 index 0000000..591b423 --- /dev/null +++ b/.idea/flaskAPI.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d3ee3a8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f72f229 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..719f287 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1730282372795 + + + + + + + + + + file://$PROJECT_DIR$/app.py + 129 + + + file://$PROJECT_DIR$/app.py + 131 + + + file://$PROJECT_DIR$/app.py + 132 + + + file://$PROJECT_DIR$/app.py + 128 + + + + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1577492 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.9-alpine +LABEL authors="Zhang Mengxu" +WORKDIR /flaskAPI +EXPOSE 5000 +COPY . . +RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple + +ENV FLASK_DEBUG=True \ + FLASK_APP=app.py \ + FLASK_RUN_HOST=0.0.0.0 \ + FLASK_ENV=development +CMD ["flask", "run"] \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..e30154f --- /dev/null +++ b/app.py @@ -0,0 +1,136 @@ +from flask import Flask, jsonify, request + +app = Flask(__name__) + +# 销售情况历史数据 +salesInfo = [ + { + "id": 1, + "year": "2024", + "month": "01", + "xse": 200000, + "tbzz": 23, + "ml": 12, + "hb": 60000, + "db": 120000, + "hd": 20000 + }, + { + "id": 2, + "year": "2024", + "month": "02", + "xse": 160000, + "tbzz": 6, + "ml": 6, + "hb": 60000, + "db": 50000, + "hd": 50000 + }, + { + "id": 3, + "year": "2024", + "month": "03", + "xse": 320000, + "tbzz": 43, + "ml": 23, + "hb": 160000, + "db": 120000, + "hd": 40000 + }, + { + "id": 4, + "year": "2024", + "month": "04", + "xse": 450000, + "tbzz": 67, + "ml": 44, + "hb": 260000, + "db": 120000, + "hd": 70000 + }, + { + "id": 5, + "year": "2024", + "month": "05", + "xse": 340000, + "tbzz": 23, + "ml": 12, + "hb": 80000, + "db": 220000, + "hd": 40000 + }, + { + "id": 6, + "year": "2024", + "month": "06", + "xse": 120000, + "tbzz": 3, + "ml": 2, + "hb": 60000, + "db": 40000, + "hd": 20000 + }, + { + "id": 7, + "year": "2024", + "month": "07", + "xse": 670000, + "tbzz": 54, + "ml": 56, + "hb": 260000, + "db": 220000, + "hd": 190000 + }, + { + "id": 8, + "year": "2024", + "month": "08", + "xse": 150000, + "tbzz": 4, + "ml": 12, + "hb": 60000, + "db": 20000, + "hd": 70000 + }, + { + "id": 9, + "year": "2024", + "month": "09", + "xse": 340000, + "tbzz": 22, + "ml": 11, + "hb": 160000, + "db": 120000, + "hd": 60000 + }, + { + "id": 10, + "year": "2024", + "month": "10", + "xse": 560000, + "tbzz": 33, + "ml": 12, + "hb": 160000, + "db": 120000, + "hd": 180000 + } +] + +@app.route('/') +def hello_world(): # put application's code here + return 'Hello World!' + +@app.route('/sales', methods=['GET']) +def get_sales(): + return jsonify(salesInfo) + +@app.route('/sale//', methods=['GET']) +def query_sale(year, month): + sale = next((s for s in salesInfo if (s['year']==str(year) and s['month']=='0'+str(month))), None) + if sale: + return jsonify(sale) + else: + return jsonify({'error': 'Sale not found'}), 404 + +if __name__ == '__main__': + app.run() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6fa2ec7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,9 @@ +blinker==1.8.2 +click==8.1.7 +Flask==3.0.3 +importlib_metadata==8.5.0 +itsdangerous==2.2.0 +Jinja2==3.1.4 +MarkupSafe==3.0.2 +Werkzeug==3.0.6 +zipp==3.20.2