|
@@ -4,6 +4,7 @@
|
|
|
# @Time :2024/12/26 08:38
|
|
|
# @Author :David
|
|
|
# @Company: shenyang JY
|
|
|
+import requests, json
|
|
|
from datetime import timedelta
|
|
|
from ftplib import FTP
|
|
|
import threading, glob, pytz
|
|
@@ -139,6 +140,7 @@ def download_zip_files_from_ftp(moment=None):
|
|
|
# 遍历文件列表,找到ZIP文件并下载
|
|
|
for file_name in files:
|
|
|
if fnmatch.fnmatch(file_name, zip_extension):
|
|
|
+ start = time.time()
|
|
|
remote_file_path = os.path.join(remote_dir, file_name)
|
|
|
local_file_path = os.path.join(local_dir, file_name)
|
|
|
|
|
@@ -148,8 +150,11 @@ def download_zip_files_from_ftp(moment=None):
|
|
|
with open(local_file_path, 'wb') as local_file:
|
|
|
logger.info(f"Downloading {remote_file_path} to {local_file_path}")
|
|
|
ftp.retrbinary(f'RETR {remote_file_path}', local_file.write)
|
|
|
-
|
|
|
- logger.info(f"时间:{now.strftime('%Y-%m-%d %H:%M:%S')},下载了 {file_name} 文件")
|
|
|
+ end = time.time()
|
|
|
+ now = datetime.datetime.now(pytz.utc).astimezone(timezone("Asia/Shanghai"))
|
|
|
+ logger_text = f"下载完成时间:{now.strftime('%Y-%m-%d %H:%M:%S')},下载 {file_name} 文件,用时 {end - start}秒"
|
|
|
+ logger.info(logger_text)
|
|
|
+ send_message(file_name, logger_text)
|
|
|
zip_file_path.append(local_file_path)
|
|
|
# 解压 ZIP 文件到临时目录
|
|
|
for zip_file_p in zip_file_path:
|
|
@@ -230,6 +235,26 @@ ftp_params = {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+def send_message(filename, text):
|
|
|
+ """
|
|
|
+ 1. 下载超时
|
|
|
+ 2. 找不到nwp
|
|
|
+ """
|
|
|
+ url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=553f02de-0ef4-49ce-8d68-2489c032d42f"
|
|
|
+ # 设置请求头
|
|
|
+ headers = {'Content-Type': 'application/json'}
|
|
|
+ text=f"""<font color=\'warning\'>算法平台解析nwp模块</font>
|
|
|
+ >文件:<font color=\'comment\'>{filename}</font>\n
|
|
|
+ >日志:<font color=\'comment\'> {text} \n</font> """
|
|
|
+ # 设置消息内容
|
|
|
+ data = {
|
|
|
+ "msgtype": "markdown",
|
|
|
+ "markdown": {
|
|
|
+ "content": text
|
|
|
+ }
|
|
|
+ }
|
|
|
+ # 发送POST请求
|
|
|
+ response = requests.post(url, headers=headers, data=json.dumps(data))
|
|
|
|
|
|
@app.route('/data_nwp_ftp', methods=['POST'])
|
|
|
def get_nwp_from_ftp():
|
|
@@ -256,6 +281,11 @@ def get_nwp_from_ftp():
|
|
|
logger.info("未找到,从日期{}时刻{}开始查找文件".format(new_date, moment))
|
|
|
success = select_file_to_mongo(args, new_date, moment)
|
|
|
i += 1
|
|
|
+ if not success:
|
|
|
+ csv_file_weather = 'meteoforce_{}_{}_weather.csv'.format(args['farmId'], date + str(moment))
|
|
|
+ logger_text = f"未找到 {csv_file_weather} 文件"
|
|
|
+ logger.info(logger_text)
|
|
|
+ send_message(csv_file_weather, logger_text)
|
|
|
except Exception as e:
|
|
|
my_exception = traceback.format_exc()
|
|
|
my_exception.replace("\n", "\t")
|
|
@@ -281,9 +311,13 @@ if __name__ == "__main__":
|
|
|
serve(app, host="0.0.0.0", port=10102)
|
|
|
print("server start!")
|
|
|
|
|
|
- # args = {"source": 'xxl', "date": '2024-12-27', 'moment': '06', 'farmId': 'J00645',
|
|
|
- # 'mongodb_database': 'db2', 'mongodb_write_table': 'j00645-d1', 'day_begin':'D0',
|
|
|
- # 'day_end': 'D13', 'isDq': True}
|
|
|
- # download_zip_files_from_ftp(hour='06')
|
|
|
- # select_file_to_mongo(args)
|
|
|
- # delete_zip_files('20241225')
|
|
|
+ # now = datetime.datetime.now(pytz.utc).astimezone(timezone("Asia/Shanghai"))
|
|
|
+ # logger_text = f"下载完成时间:{now.strftime('%Y-%m-%d %H:%M:%S')},下载 20230323-meteoforece-nwp.zip 文件,用时 {700/60:.2f}分钟"
|
|
|
+ # logger.info(logger_text)
|
|
|
+ # send_message('20230323-meteoforece-nwp.zip', logger_text)
|
|
|
+
|
|
|
+ # farmId, isDq = 'j01096', 1
|
|
|
+ # date, moment = get_moment_next()
|
|
|
+ # csv_file_weather = 'meteoforce_{}_{}_weather.csv'.format(farmId, date + str(moment))
|
|
|
+ # logger_text = f"未找到 {csv_file_weather} 文件"
|
|
|
+ # send_message(csv_file_weather, logger_text)
|