第一次提交

This commit is contained in:
尹舟 2025-02-11 16:04:10 +08:00
commit 54b723fefd
8 changed files with 199 additions and 0 deletions

4
.dockerignore Normal file
View File

@ -0,0 +1,4 @@
.venv/
.idea/
.deploy/
logs/

14
docker-compose.yaml Normal file
View File

@ -0,0 +1,14 @@
version: '3.4'
services:
sql-runner:
build:
context: .
dockerfile: Dockerfile
restart: always
container_name: yin_home
image: registry.cn-hangzhou.aliyuncs.com/yinzhou_docker_hub/yin_home:latest
ports:
- "1314:1314"
# docker-compose up --build

20
dockerfile Normal file
View File

@ -0,0 +1,20 @@
# 使用阿里云的 Python 3.11 镜像
FROM registry.cn-hangzhou.aliyuncs.com/yinzhou_docker_hub/python:3.11-alpine
# 设置工作目录
WORKDIR /opt/yin_home
# 设置时区为 Asia/Shanghai
ENV TZ=Asia/Shanghai
# 将 requirements.txt 文件复制到容器中
COPY requirements.txt .
# 安装依赖
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
# 将其他文件复制到容器中
COPY . .
# 运行应用程序
ENTRYPOINT ["python3", "run.py"]

BIN
requirements.txt Normal file

Binary file not shown.

40
run.py Normal file
View File

@ -0,0 +1,40 @@
from flask import Flask
from utils import query_weather
from utils.log import Log
app = Flask(__name__)
@app.route('/weather', methods=['GET'])
def weather():
log = Log().getlog()
response = query_weather.query_weather()
log.info(response)
return response, 200
@app.route('/weather_all', methods=['GET'])
def weather_all():
log = Log().getlog()
response = query_weather.query_weather(extensions='all')
log.info(response)
return response, 200
@app.route('/weather_flag', methods=['GET'])
def weather_flag():
log = Log().getlog()
response = query_weather.query_weather()
log.info(response)
weather = response['lives'][0]['weather']
# weather包含雨字符串
if '' in weather:
return {"weather":1}, 200
else:
return {"weather":0}, 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=1314, debug=False)

40
sqllineage.py Normal file
View File

@ -0,0 +1,40 @@
from flask import Flask, render_template, request, jsonify
from utils.sql_parse import parse_create_table_sql
from utils.log import Log
app = Flask(__name__)
log = Log().getlog()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/convert', methods=['POST'])
def convert_sql():
sql_input = request.form['sql']
if sql_input.strip()=='':
return jsonify({
'parsed_result': "请在上面输入框输入hologres建表语句",
'message': 'SQL processed.'
})
hologres_connection = request.form['hologresConnection']
log.info("SQL Input: %s", sql_input)
log.info("SQL hologres_connection: %s", hologres_connection)
try:
parsed_result=parse_create_table_sql(sql_input,hologres_connection)
result = {
'parsed_result': parsed_result,
'message': 'SQL processed successfully.'
}
except Exception as e:
result = {'error': f'请检查输入sql:\n\n {str(e)}'}
log.info("SQL result: %s", result)
return jsonify(result)
if __name__ == '__main__':
# 指定host和port这里使用0.0.0.0可以让服务器被外部访问
app.run(host='0.0.0.0', port=8778, debug=True)

69
utils/log.py Normal file
View File

@ -0,0 +1,69 @@
import logging
import os
from datetime import datetime
# 定义全局变量 log_path
cur_path = os.path.dirname(os.path.realpath(__file__))
log_path = os.path.join(os.path.dirname(cur_path), 'logs')
class Log():
def __init__(self, logger_name='my_logger'):
self.logger = logging.getLogger(logger_name)
if self.logger.hasHandlers():
self.logger.handlers.clear()
self.logger.setLevel(logging.INFO)
if not os.path.exists(log_path):
os.makedirs(log_path)
self.update_log_file()
def update_log_file(self):
current_date = datetime.now().strftime("%Y_%m_%d")
self.log_name = os.path.join(log_path, f'{current_date}.log')
for handler in self.logger.handlers[:]:
self.logger.removeHandler(handler)
fh = logging.FileHandler(self.log_name, 'a', encoding='utf-8')
fh.setLevel(logging.INFO)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
formatter = logging.Formatter(
'[%(asctime)s] %(filename)s line:%(lineno)d [%(levelname)s]%(message)s',
datefmt="%Y-%m-%d %H:%M:%S"
)
fh.setFormatter(formatter)
ch.setFormatter(formatter)
self.logger.addHandler(fh)
self.logger.addHandler(ch)
def getlog(self):
current_date = datetime.now().strftime("%Y_%m_%d")
log_date = os.path.basename(self.log_name).split('.')[0]
if current_date != log_date:
self.update_log_file()
return self.logger
def info(self, msg, *args, **kwargs):
logger = self.getlog()
logger.info(msg, *args, **kwargs)
def error(self, msg, *args, **kwargs):
logger = self.getlog()
logger.error(msg, *args, **kwargs)
def warning(self, msg, *args, **kwargs):
logger = self.getlog()
logger.warning(msg, *args, **kwargs)
if __name__ == "__main__":
log = Log()
log.info("---测试开始----")
log.error("操作步骤1,2,3")
log.warning("----测试结束----")

12
utils/query_weather.py Normal file
View File

@ -0,0 +1,12 @@
import requests
def query_weather(key="3add99f10c5144ebd64bfa0bfb6b1c20", city="420115", extensions="base", output="JSON"):
url = "https://restapi.amap.com/v3/weather/weatherInfo"
querystring = {"key": key, "city": city, "extensions": extensions,
"output": output}
response = requests.request("GET", url, params=querystring)
return response.json()