修改上传时间为年月日时分秒
This commit is contained in:
60
scheduler.py
60
scheduler.py
@@ -29,15 +29,7 @@ def update_file_status(username, from_status, to_status):
|
||||
try:
|
||||
with open(TIME_FILE_PATH, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
# new_lines = []
|
||||
# for line in lines:
|
||||
# clean_line = line.strip()
|
||||
# # 匹配逻辑:包含用户名 且 以 from_status 结尾
|
||||
# if f" {username} " in line and clean_line.endswith(from_status):
|
||||
# line = line.replace(from_status, to_status)
|
||||
# success = True
|
||||
# new_lines.append(line)
|
||||
|
||||
new_lines = []
|
||||
for line in lines:
|
||||
# 使用正则确保精准匹配用户名和结尾状态
|
||||
@@ -73,7 +65,7 @@ def parse_time_config():
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
# 匹配:用户名 时间 true (仅获取待处理任务)
|
||||
match = re.search(r'(\w+)\s+(\d{1,2}:\d{2}:\d{2})\s+ok$', line)
|
||||
match = re.search(r'(\w+)\s+(\d{4}-\d{1,2}-\d{1,2}\s+\d{1,2}:\d{2}:\d{2})\s+ok$', line)
|
||||
if match:
|
||||
username, scheduled_time = match.group(1), match.group(2)
|
||||
time_map[username] = scheduled_time
|
||||
@@ -81,6 +73,39 @@ def parse_time_config():
|
||||
print(f"❌ 解析 time.txt 失败: {e}")
|
||||
return time_map
|
||||
|
||||
|
||||
|
||||
def normalize_datetime(time_str):
|
||||
"""
|
||||
将时间字符串格式化为标准格式:YYYY-MM-DD HH:MM:SS
|
||||
补全单数字的月、日、时
|
||||
例如:2024-1-15 9:52:20 -> 2024-01-15 09:52:20
|
||||
"""
|
||||
try:
|
||||
# 分割日期和时间部分
|
||||
if ' ' in time_str:
|
||||
date_part, time_part = time_str.split(' ', 1)
|
||||
|
||||
# 补全日期部分的单数字
|
||||
date_parts = date_part.split('-')
|
||||
if len(date_parts) == 3:
|
||||
year = date_parts[0]
|
||||
month = date_parts[1].zfill(2) # 月补零
|
||||
day = date_parts[2].zfill(2) # 日补零
|
||||
date_part = f"{year}-{month}-{day}"
|
||||
|
||||
# 补全时间部分的单数字小时
|
||||
time_parts = time_part.split(':')
|
||||
if len(time_parts) >= 1:
|
||||
hour = time_parts[0].zfill(2) # 小时补零
|
||||
time_part = f"{hour}:{':'.join(time_parts[1:])}"
|
||||
|
||||
return f"{date_part} {time_part}"
|
||||
return time_str
|
||||
except Exception as e:
|
||||
print(f"⚠️ 时间格式标准化失败 ({time_str}): {e}")
|
||||
return time_str
|
||||
|
||||
def get_combined_tasks():
|
||||
"""
|
||||
结合接口(is_ok==1)和本地文件(ok)筛选任务
|
||||
@@ -96,10 +121,10 @@ def get_combined_tasks():
|
||||
return {}
|
||||
|
||||
task_list = {}
|
||||
today = datetime.now().strftime("%Y-%m-%d")
|
||||
# today = datetime.now().strftime("%Y-%m-%d")
|
||||
|
||||
for account in accounts:
|
||||
if account.get('is_ok') == 1 or account.get('username') == "CZSCZQ13A1xuliguo":
|
||||
if account.get('is_ok') == 1:
|
||||
user = account.get('username')
|
||||
ip = account.get('device_ip')
|
||||
port = account.get('device_port')
|
||||
@@ -111,12 +136,13 @@ def get_combined_tasks():
|
||||
# 确保时间是两位数格式
|
||||
raw_time = local_times[user]
|
||||
# 将时间格式化为两位数:9:52:20 -> 09:52:20
|
||||
if ':' in raw_time:
|
||||
parts = raw_time.split(':')
|
||||
if len(parts[0]) == 1:
|
||||
raw_time = f"0{raw_time}" # 补齐前导零
|
||||
# if ':' in raw_time:
|
||||
# parts = raw_time.split(':')
|
||||
# if len(parts[0]) == 1:
|
||||
# raw_time = f"0{raw_time}" # 补齐前导零
|
||||
|
||||
full_time = f"{today} {raw_time}"
|
||||
# full_time = f"{today} {raw_time}"
|
||||
full_time = normalize_datetime(raw_time)
|
||||
task_list[address] = {"time": full_time, "user": user}
|
||||
|
||||
return task_list
|
||||
|
||||
Reference in New Issue
Block a user