fix(law_monitor): AppleScript f-string 제거 + EU 파일명 고유화
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -210,33 +210,32 @@ def _should_run(last_check: dict, key: str, interval_days: int) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def _import_foreign_to_devonthink(filepath: Path, title: str, country: str):
|
def _import_foreign_to_devonthink(filepath: Path, title: str, country: str):
|
||||||
"""외국 법령 DEVONthink 임포트"""
|
"""외국 법령 DEVONthink 임포트 — 파일 경로만 사용 (특수문자 안전)"""
|
||||||
country_map = {"US": "US", "JP": "JP", "EU": "EU"}
|
folder = {"US": "US", "JP": "JP", "EU": "EU"}.get(country, country)
|
||||||
folder = country_map.get(country, country)
|
fp = str(filepath)
|
||||||
escaped_path = str(filepath).replace('\\', '\\\\').replace('"', '\\"')
|
script = (
|
||||||
escaped_title = title.replace('\\', '').replace('"', '').replace("'", "")[:60]
|
'tell application id "DNtp"\n'
|
||||||
script = f'''
|
' set targetDB to missing value\n'
|
||||||
tell application id "DNtp"
|
' repeat with db in databases\n'
|
||||||
set targetDB to missing value
|
' if name of db is "04_Industrial safety" then\n'
|
||||||
repeat with db in databases
|
' set targetDB to db\n'
|
||||||
if name of db is "04_Industrial safety" then
|
' exit repeat\n'
|
||||||
set targetDB to db
|
' end if\n'
|
||||||
exit repeat
|
' end repeat\n'
|
||||||
end if
|
' if targetDB is not missing value then\n'
|
||||||
end repeat
|
f' set targetGroup to create location "/10_Legislation/Foreign/{folder}" in targetDB\n'
|
||||||
if targetDB is not missing value then
|
f' set theRecord to import POSIX path "{fp}" to targetGroup\n'
|
||||||
set targetGroup to create location "/10_Legislation/Foreign/{folder}" in targetDB
|
' set tags of theRecord to {"#주제/산업안전/법령", "$유형/법령", "' + country + '"}\n'
|
||||||
set theRecord to import POSIX path "{escaped_path}" to targetGroup
|
' add custom meta data "law_monitor" for "sourceChannel" to theRecord\n'
|
||||||
set tags of theRecord to {{"#주제/산업안전/법령", "$유형/법령", "{country}"}}
|
' add custom meta data "external" for "dataOrigin" to theRecord\n'
|
||||||
add custom meta data "law_monitor" for "sourceChannel" to theRecord
|
' add custom meta data (current date) for "lastAIProcess" to theRecord\n'
|
||||||
add custom meta data "external" for "dataOrigin" to theRecord
|
' end if\n'
|
||||||
add custom meta data (current date) for "lastAIProcess" to theRecord
|
'end tell'
|
||||||
end if
|
)
|
||||||
end tell
|
|
||||||
'''
|
|
||||||
try:
|
try:
|
||||||
run_applescript_inline(script)
|
run_applescript_inline(script)
|
||||||
logger.info(f"DEVONthink 임포트 [{country}]: {escaped_title}")
|
safe_title = title[:40].replace('\n', ' ')
|
||||||
|
logger.info(f"DEVONthink 임포트 [{country}]: {safe_title}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"DEVONthink 임포트 실패 [{country}]: {e}")
|
logger.error(f"DEVONthink 임포트 실패 [{country}]: {e}")
|
||||||
|
|
||||||
@@ -386,9 +385,9 @@ def fetch_eu_osha(last_check: dict) -> int:
|
|||||||
if description:
|
if description:
|
||||||
content += f"## Summary\n\n{description}\n"
|
content += f"## Summary\n\n{description}\n"
|
||||||
|
|
||||||
safe_title = "".join(c if c.isalnum() or c in " _-" else "_" for c in title)[:50]
|
safe_title = "".join(c if c.isalnum() or c in " _-" else "" for c in title)[:50].strip() or f"item{count+1}"
|
||||||
today = datetime.now().strftime("%Y%m%d")
|
today = datetime.now().strftime("%Y%m%d")
|
||||||
filepath = LAWS_DIR / f"EU_{today}_{safe_title}.md"
|
filepath = LAWS_DIR / f"EU_{today}_{count+1:02d}_{safe_title}.md"
|
||||||
with open(filepath, "w", encoding="utf-8") as f:
|
with open(filepath, "w", encoding="utf-8") as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user