feat(core): initial commit unified architecture (scud_ai v2.5 with modular web_api)
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import os
|
||||
import shutil
|
||||
from config import DATE_TODAY, DATE_YESTERDAY, ZUP_1C_DIR, SHARE_1C_DIR
|
||||
|
||||
|
||||
def find_file_strictly_on_share(prefix, date_str):
|
||||
"""
|
||||
Ищет файл со строгой привязкой ТОЛЬКО к сетевой шаре SHARE_1C_DIR,
|
||||
не обращаясь к локальным папкам.
|
||||
"""
|
||||
if not os.path.exists(SHARE_1C_DIR):
|
||||
return None
|
||||
|
||||
date_dots = date_str
|
||||
date_underscores = date_str.replace('.', '_')
|
||||
|
||||
try:
|
||||
for f in os.listdir(SHARE_1C_DIR):
|
||||
if f.endswith('.xlsx') or f.endswith('.csv'):
|
||||
if f.lower().startswith(prefix.lower()):
|
||||
if date_dots in f or date_underscores in f:
|
||||
return os.path.join(SHARE_1C_DIR, f)
|
||||
except Exception as e:
|
||||
print(f" [⚠️] Ошибка чтения сетевой шары: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def copy_1c_files_from_share():
|
||||
r"""
|
||||
Копирует свежие файлы 1С (Штат и Отсутствия) за Сегодня и Вчера
|
||||
из сетевой шары \\storage\SCUD\Обмен\Штат в локальную папку data/1c/
|
||||
"""
|
||||
print(f"[0.5/5] Проверка и копирование файлов 1С с шары: {SHARE_1C_DIR}...")
|
||||
|
||||
if not os.path.exists(SHARE_1C_DIR):
|
||||
print(f"[⚠️] Сетевой шар недоступен или путь не найден: {SHARE_1C_DIR}")
|
||||
print(" Используем ранее сохраненные локальные файлы из data/1c/\n")
|
||||
return False
|
||||
|
||||
dates_to_copy = [DATE_TODAY, DATE_YESTERDAY]
|
||||
prefixes = ["Штат", "Отсутствия"]
|
||||
copied_count = 0
|
||||
|
||||
os.makedirs(ZUP_1C_DIR, exist_ok=True)
|
||||
|
||||
for d_str in dates_to_copy:
|
||||
for prefix in prefixes:
|
||||
remote_file = find_file_strictly_on_share(prefix, d_str)
|
||||
|
||||
if remote_file and os.path.exists(remote_file):
|
||||
filename = os.path.basename(remote_file)
|
||||
local_target_path = os.path.join(ZUP_1C_DIR, filename)
|
||||
|
||||
try:
|
||||
shutil.copy2(remote_file, local_target_path)
|
||||
print(f" [✓] Успешно скопирован с шары: {filename} -> data/1c/")
|
||||
copied_count += 1
|
||||
except Exception as e:
|
||||
print(f" [⚠️] Ошибка копирования {filename}: {e}")
|
||||
else:
|
||||
d_fmt = d_str.replace('.', '_')
|
||||
print(f" [ℹ️] На сетевой шаре отсутствует {prefix} за {d_str} ({prefix}_{d_fmt}.xlsx)")
|
||||
|
||||
if copied_count > 0:
|
||||
print(f"[✓] Успешно скопировано файлов с сетевой шары: {copied_count} шт.\n")
|
||||
else:
|
||||
print("[ℹ️] Новых файлов за указанные даты на сетевой шаре не обнаружено.\n")
|
||||
|
||||
return True
|
||||
Reference in New Issue
Block a user