项目文件
This commit is contained in:
21
.idea/flaskAPI.iml
generated
Normal file
21
.idea/flaskAPI.iml
generated
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="Flask">
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
<component name="TemplatesService">
|
||||||
|
<option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
|
||||||
|
<option name="TEMPLATE_FOLDERS">
|
||||||
|
<list>
|
||||||
|
<option value="$MODULE_DIR$/templates" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.9 (flaskAPI)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (flaskAPI)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/flaskAPI.iml" filepath="$PROJECT_DIR$/.idea/flaskAPI.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
149
.idea/workspace.xml
generated
Normal file
149
.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AutoImportSettings">
|
||||||
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
|
</component>
|
||||||
|
<component name="ChangeListManager">
|
||||||
|
<list default="true" id="c69c4d37-6f84-4453-8bc1-0b4bae08d1f5" name="Changes" comment="">
|
||||||
|
<change afterPath="$PROJECT_DIR$/.idea/flaskAPI.iml" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/Dockerfile" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/app.py" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
|
||||||
|
</list>
|
||||||
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
|
</component>
|
||||||
|
<component name="FileTemplateManagerImpl">
|
||||||
|
<option name="RECENT_TEMPLATES">
|
||||||
|
<list>
|
||||||
|
<option value="Flask Main" />
|
||||||
|
<option value="Dockerfile" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="Git.Settings">
|
||||||
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectColorInfo"><![CDATA[{
|
||||||
|
"associatedIndex": 4
|
||||||
|
}]]></component>
|
||||||
|
<component name="ProjectId" id="2o9Wf6oXZf8OICllJSk5fZvxViE" />
|
||||||
|
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||||
|
<component name="ProjectViewState">
|
||||||
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
|
<option name="showLibraryContents" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
|
"keyToString": {
|
||||||
|
"Flask server.Flask (app.py).executor": "Debug",
|
||||||
|
"Flask server.flaskAPI.executor": "Run",
|
||||||
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
|
"git-widget-placeholder": "main",
|
||||||
|
"node.js.detected.package.eslint": "true",
|
||||||
|
"node.js.detected.package.tslint": "true",
|
||||||
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
|
"nodejs_package_manager_path": "npm",
|
||||||
|
"vue.rearranger.settings.migration": "true"
|
||||||
|
}
|
||||||
|
}]]></component>
|
||||||
|
<component name="RunManager" selected="Flask server.flaskAPI">
|
||||||
|
<configuration name="Flask (app.py)" type="Python.FlaskServer" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="flaskAPI" />
|
||||||
|
<option name="target" value="$PROJECT_DIR$/app.py" />
|
||||||
|
<option name="targetType" value="PATH" />
|
||||||
|
<option name="ENV_FILES" value="" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<option name="SDK_HOME" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="" />
|
||||||
|
<option name="IS_MODULE_SDK" value="true" />
|
||||||
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
|
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||||
|
<option name="launchJavascriptDebuger" value="false" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
<configuration name="flaskAPI" type="Python.FlaskServer">
|
||||||
|
<module name="flaskAPI" />
|
||||||
|
<option name="target" value="$PROJECT_DIR$/app.py" />
|
||||||
|
<option name="targetType" value="PATH" />
|
||||||
|
<option name="ENV_FILES" value="" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<option name="SDK_HOME" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="" />
|
||||||
|
<option name="IS_MODULE_SDK" value="false" />
|
||||||
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
|
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||||
|
<option name="launchJavascriptDebuger" value="false" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
<recent_temporary>
|
||||||
|
<list>
|
||||||
|
<item itemvalue="Flask server.Flask (app.py)" />
|
||||||
|
</list>
|
||||||
|
</recent_temporary>
|
||||||
|
</component>
|
||||||
|
<component name="SharedIndexes">
|
||||||
|
<attachedChunks>
|
||||||
|
<set>
|
||||||
|
<option value="bundled-js-predefined-d6986cc7102b-5c90d61e3bab-JavaScript-PY-242.23339.19" />
|
||||||
|
<option value="bundled-python-sdk-0029f7779945-399fe30bd8c1-com.jetbrains.pycharm.pro.sharedIndexes.bundled-PY-242.23339.19" />
|
||||||
|
</set>
|
||||||
|
</attachedChunks>
|
||||||
|
</component>
|
||||||
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||||
|
<component name="TaskManager">
|
||||||
|
<task active="true" id="Default" summary="Default task">
|
||||||
|
<changelist id="c69c4d37-6f84-4453-8bc1-0b4bae08d1f5" name="Changes" comment="" />
|
||||||
|
<created>1730282372795</created>
|
||||||
|
<option name="number" value="Default" />
|
||||||
|
<option name="presentableId" value="Default" />
|
||||||
|
<updated>1730282372795</updated>
|
||||||
|
<workItem from="1730282380540" duration="7266000" />
|
||||||
|
</task>
|
||||||
|
<servers />
|
||||||
|
</component>
|
||||||
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
<option name="version" value="3" />
|
||||||
|
</component>
|
||||||
|
<component name="XDebuggerManager">
|
||||||
|
<breakpoint-manager>
|
||||||
|
<breakpoints>
|
||||||
|
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
||||||
|
<url>file://$PROJECT_DIR$/app.py</url>
|
||||||
|
<line>129</line>
|
||||||
|
<option name="timeStamp" value="1" />
|
||||||
|
</line-breakpoint>
|
||||||
|
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
||||||
|
<url>file://$PROJECT_DIR$/app.py</url>
|
||||||
|
<line>131</line>
|
||||||
|
<option name="timeStamp" value="2" />
|
||||||
|
</line-breakpoint>
|
||||||
|
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
||||||
|
<url>file://$PROJECT_DIR$/app.py</url>
|
||||||
|
<line>132</line>
|
||||||
|
<option name="timeStamp" value="3" />
|
||||||
|
</line-breakpoint>
|
||||||
|
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
||||||
|
<url>file://$PROJECT_DIR$/app.py</url>
|
||||||
|
<line>128</line>
|
||||||
|
<option name="timeStamp" value="4" />
|
||||||
|
</line-breakpoint>
|
||||||
|
</breakpoints>
|
||||||
|
</breakpoint-manager>
|
||||||
|
</component>
|
||||||
|
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||||
|
<SUITE FILE_PATH="coverage/flaskAPI$Flask__app_py_.coverage" NAME="Flask (app.py) Coverage Results" MODIFIED="1730292662210" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
|
||||||
|
<SUITE FILE_PATH="coverage/flaskAPI$flaskAPI.coverage" NAME="flaskAPI Coverage Results" MODIFIED="1730292739634" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
|
||||||
|
</component>
|
||||||
|
</project>
|
12
Dockerfile
Normal file
12
Dockerfile
Normal file
@@ -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"]
|
136
app.py
Normal file
136
app.py
Normal file
@@ -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/<int:year>/<int:month>', 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()
|
9
requirements.txt
Normal file
9
requirements.txt
Normal file
@@ -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
|
Reference in New Issue
Block a user