diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..289fcbf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM python:3.11-slim + +WORKDIR /app + +# 1. 安装系统编译依赖(qqwry-py3 需要编译) +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + libffi-dev \ + libssl-dev \ + python3-dev \ + && rm -rf /var/lib/apt/lists/* + +# 2. 复制并安装 Python 依赖 +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# 3. 复制源码 & 纯真库 +COPY qqwry.dat app.py ./ + +# 4. 默认端口 5000,可 docker run -e PORT=8080 覆盖 +ENV PORT=5000 +EXPOSE ${PORT} + +# 5. 直接 python 启动 +CMD ["python", "app.py"] diff --git a/app.py b/app.py new file mode 100644 index 0000000..c0fa18e --- /dev/null +++ b/app.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python3 +""" +RESTful API + 响应式 WebUI(手机优先) +自动把用户公网 IP 填到输入框 +依赖:flask>=3.0.0 qqwry-py3>=1.2.1 +""" +import os +from flask import Flask, jsonify, request + +app = Flask(__name__) + +# 1. 加载纯真库 +from qqwry import QQwry +q = QQwry() +dat_path = os.path.join(os.path.dirname(__file__), "qqwry.dat") +q.load_file(dat_path) + +# 2. API:查询 IP +@app.route("/ip/", methods=["GET"]) +def query_ip(ip: str): + country, area = q.lookup(ip) + return jsonify(ip=ip, country=country or None, area=area or None) + +# 3. API:健康检查 +@app.route("/health", methods=["GET"]) +def health(): + return "ok" + +# 4. 响应式 WebUI(手机优先)+ 自动获取客户端公网 IP +UI_HTML = """ + + + + + 纯真 IP 查询 + + + +
+
+

纯真 IP 查询

+
+ + +
+ +
+
+
数据提供:纯真 IP 库
+
+ + + +""" + +@app.route("/ui") +def ui(): + return UI_HTML + +@app.route("/") +def index(): + return """""" + +# 5. 启动 +if __name__ == "__main__": + app.run(host="0.0.0.0", + port=int(os.getenv("PORT", 5000)), + debug=False) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c5168f4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + app: + build: . + container_name: czip-api + restart: unless-stopped + ports: + - "5000:5000" + environment: + - PORT=5000 diff --git a/qqwry.dat b/qqwry.dat new file mode 100644 index 0000000..924b3eb Binary files /dev/null and b/qqwry.dat differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4af833e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask==3.0.0 +qqwry-py3==1.2.1