jack преди 1 година
ревизия
a081d42e4c
променени са 2 файла, в които са добавени 92 реда и са изтрити 0 реда
  1. 62 0
      .gitignore
  2. 30 0
      main.py

+ 62 - 0
.gitignore

@@ -0,0 +1,62 @@
+.DS_Store
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+.idea/*
+config.json
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*,cover
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+

+ 30 - 0
main.py

@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+
+from fastapi import FastAPI, HTTPException
+from fastapi.responses import FileResponse
+from pathlib import Path
+import os
+
+app = FastAPI()
+
+# 假设你的XML文件文件夹路径是 "xml_file"
+xml_folder_path = Path("/Users/jack/source/mySpace/mycode/my_project/spider_rss/xml_file")
+
+
+@app.get("/{filename}")
+async def read_xml(filename: str):
+    # 构建完整的文件路径
+    file_path = xml_folder_path / f"{filename}.xml"
+
+    # 检查文件是否存在
+    if not file_path.is_file():
+        raise HTTPException(status_code=404, detail="File not found")
+
+    # 返回文件响应
+    return FileResponse(file_path, media_type="application/xml")
+
+
+if __name__ == "__main__":
+    import uvicorn
+
+    uvicorn.run(app, host="0.0.0.0", port=8000)