From 443a56364d21cd27392f1f705bf12052cd35df7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=9D=E5=B7=9D?= Date: Wed, 8 Dec 2021 14:40:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=20=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 14 ++++++++++++++ Dockerfile | 6 ++++++ common/__init__.py | 0 common/scripts.py | 21 +++++++++++++++++++++ company/__init__.py | 0 company/db.py | 0 company/routes.py | 20 ++++++++++++++++++++ company/scripts.py | 9 +++++++++ gunicorn.conf.py | 8 ++++++++ rating/__init__.py | 0 requirements.txt | 6 ++++++ setting.py | 6 ++++++ 12 files changed, 90 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 Dockerfile create mode 100644 common/__init__.py create mode 100644 common/scripts.py create mode 100644 company/__init__.py create mode 100644 company/db.py create mode 100644 company/routes.py create mode 100644 company/scripts.py create mode 100644 gunicorn.conf.py create mode 100644 rating/__init__.py create mode 100644 requirements.txt create mode 100644 setting.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..4b1b554 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,14 @@ +stages: + - deploy + +job: + stage: deploy + script: + - docker stop etl_tfse + - docker rm etl_tfse + - docker build -t etl_tfse . + - docker run -d -p 51011:51011 --name etl_tfse -v /etc/timezone:/etc/timezone:ro -v /etc/localtime:/etc/localtime:ro etl_tfse + only: + - master + tags: + - etl_tfse diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e0cd182 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.8 +WORKDIR /usr/src/app/etl_tfse +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.mirrors.ustc.edu.cn/simple +COPY . . +CMD ["gunicorn", "app:app", "-c", "./gunicorn.conf.py"] diff --git a/common/__init__.py b/common/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/common/scripts.py b/common/scripts.py new file mode 100644 index 0000000..5dac4df --- /dev/null +++ b/common/scripts.py @@ -0,0 +1,21 @@ +import functools + +from flask import request + +from setting import API_SECRET + + +def verify_token(func): + """ + 校验token + """ + @functools.wraps(func) + def internal(*args, **kwargs): + try: + token = request.headers.get('token') + if token != API_SECRET: + return {"info": "接口密钥错误"}, 401 + except Exception: + return {"info": "请求异常"}, 401 + return func(*args, **kwargs) + return internal diff --git a/company/__init__.py b/company/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/company/db.py b/company/db.py new file mode 100644 index 0000000..e69de29 diff --git a/company/routes.py b/company/routes.py new file mode 100644 index 0000000..40fc9a3 --- /dev/null +++ b/company/routes.py @@ -0,0 +1,20 @@ +from flask import Blueprint, request, Response + +from common.scripts import verify_token +from company.scripts import * + +company_route = Blueprint('company', __name__) + + +@company_route.route('/basic_info', methods=['POST']) +@verify_token +def basic_info(): + """ + 基础信息清晰 + Parameters: + company_name 企业名称 + Returns: + res: desc + """ + company_name = request.json['company_name'] + basic_info_etl(company_name) diff --git a/company/scripts.py b/company/scripts.py new file mode 100644 index 0000000..06f8fb0 --- /dev/null +++ b/company/scripts.py @@ -0,0 +1,9 @@ +def basic_info_etl(param): + """ + 根据企业名称,查询天眼查数据库 + 将数据按规定格式存储到股交企业数据库中 + Parameters: + param: desc + Returns: + res: desc + """ \ No newline at end of file diff --git a/gunicorn.conf.py b/gunicorn.conf.py new file mode 100644 index 0000000..5e52a68 --- /dev/null +++ b/gunicorn.conf.py @@ -0,0 +1,8 @@ +from setting import APP_PORT + +# 并行工作进程数 +workers = 10 +# 监听内网端口 +bind = '0.0.0.0:{}'.format(APP_PORT) +# 工作模式协程 +worker_class = 'gevent' diff --git a/rating/__init__.py b/rating/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..65da487 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +flask~=1.1.2 +flask_cors +gunicorn +gevent +pymongo~=3.11.0 +requests~=2.25.1 diff --git a/setting.py b/setting.py new file mode 100644 index 0000000..01c4b96 --- /dev/null +++ b/setting.py @@ -0,0 +1,6 @@ +# 应用配置 +APP_NAME = 'etl_tfse' +APP_PORT = '51011' + +# 接口密钥 +API_SECRET = "dmfd7FshT!5Wng9^gcCcQV7T6FBnVgl4"