fix: AppleScript POSIX path 변수 방식 + 단일 -e 실행으로 따옴표 문제 해결
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -110,27 +110,22 @@ def save_law_file(law_name: str, content: str) -> Path:
|
|||||||
|
|
||||||
|
|
||||||
def import_to_devonthink(filepath: Path, law_name: str, category: str):
|
def import_to_devonthink(filepath: Path, law_name: str, category: str):
|
||||||
"""DEVONthink 04_Industrial Safety로 임포트"""
|
"""DEVONthink 04_Industrial Safety로 임포트 — 변수 방식"""
|
||||||
script = f'''
|
fp = str(filepath)
|
||||||
tell application id "DNtp"
|
script = f'set fp to "{fp}"\n'
|
||||||
set targetDB to missing value
|
script += 'tell application id "DNtp"\n'
|
||||||
repeat with db in databases
|
script += ' repeat with db in databases\n'
|
||||||
if name of db is "04_Industrial safety" then
|
script += ' if name of db is "04_Industrial safety" then\n'
|
||||||
set targetDB to db
|
script += ' set targetGroup to create location "/10_Legislation/Law" in db\n'
|
||||||
exit repeat
|
script += ' set theRecord to import fp to targetGroup\n'
|
||||||
end if
|
script += f' set tags of theRecord to {{"#주제/산업안전/법령", "$유형/법령", "{category}"}}\n'
|
||||||
end repeat
|
script += ' add custom meta data "law_monitor" for "sourceChannel" to theRecord\n'
|
||||||
|
script += ' add custom meta data "external" for "dataOrigin" to theRecord\n'
|
||||||
if targetDB is not missing value then
|
script += ' add custom meta data (current date) for "lastAIProcess" to theRecord\n'
|
||||||
set targetGroup to create location "/10_Legislation/Law" in targetDB
|
script += ' exit repeat\n'
|
||||||
set theRecord to import POSIX path "{filepath}" to targetGroup
|
script += ' end if\n'
|
||||||
set tags of theRecord to {{"#주제/산업안전/법령", "$유형/법령", "{category}"}}
|
script += ' end repeat\n'
|
||||||
add custom meta data "law_monitor" for "sourceChannel" to theRecord
|
script += 'end tell'
|
||||||
add custom meta data "external" for "dataOrigin" to theRecord
|
|
||||||
add custom meta data (current date) for "lastAIProcess" to theRecord
|
|
||||||
end if
|
|
||||||
end tell
|
|
||||||
'''
|
|
||||||
try:
|
try:
|
||||||
run_applescript_inline(script)
|
run_applescript_inline(script)
|
||||||
logger.info(f"DEVONthink 임포트 완료: {law_name}")
|
logger.info(f"DEVONthink 임포트 완료: {law_name}")
|
||||||
@@ -210,28 +205,23 @@ 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 임포트 — 변수 방식 (POSIX path 따옴표 문제 회피)"""
|
||||||
folder = {"US": "US", "JP": "JP", "EU": "EU"}.get(country, country)
|
folder = {"US": "US", "JP": "JP", "EU": "EU"}.get(country, country)
|
||||||
fp = str(filepath)
|
fp = str(filepath)
|
||||||
script = (
|
script = f'set fp to "{fp}"\n'
|
||||||
'tell application id "DNtp"\n'
|
script += 'tell application id "DNtp"\n'
|
||||||
' set targetDB to missing value\n'
|
script += ' repeat with db in databases\n'
|
||||||
' repeat with db in databases\n'
|
script += ' if name of db is "04_Industrial safety" then\n'
|
||||||
' if name of db is "04_Industrial safety" then\n'
|
script += f' set targetGroup to create location "/10_Legislation/Foreign/{folder}" in db\n'
|
||||||
' set targetDB to db\n'
|
script += ' set theRecord to import fp to targetGroup\n'
|
||||||
' exit repeat\n'
|
script += f' set tags of theRecord to {{"#주제/산업안전/법령", "$유형/법령", "{country}"}}\n'
|
||||||
' end if\n'
|
script += ' add custom meta data "law_monitor" for "sourceChannel" to theRecord\n'
|
||||||
' end repeat\n'
|
script += ' add custom meta data "external" for "dataOrigin" to theRecord\n'
|
||||||
' if targetDB is not missing value then\n'
|
script += ' add custom meta data (current date) for "lastAIProcess" to theRecord\n'
|
||||||
f' set targetGroup to create location "/10_Legislation/Foreign/{folder}" in targetDB\n'
|
script += ' exit repeat\n'
|
||||||
f' set theRecord to import POSIX path "{fp}" to targetGroup\n'
|
script += ' end if\n'
|
||||||
' set tags of theRecord to {"#주제/산업안전/법령", "$유형/법령", "' + country + '"}\n'
|
script += ' end repeat\n'
|
||||||
' add custom meta data "law_monitor" for "sourceChannel" to theRecord\n'
|
script += 'end tell'
|
||||||
' add custom meta data "external" for "dataOrigin" to theRecord\n'
|
|
||||||
' add custom meta data (current date) for "lastAIProcess" to theRecord\n'
|
|
||||||
' end if\n'
|
|
||||||
'end tell'
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
run_applescript_inline(script)
|
run_applescript_inline(script)
|
||||||
safe_title = title[:40].replace('\n', ' ')
|
safe_title = title[:40].replace('\n', ' ')
|
||||||
|
|||||||
@@ -94,11 +94,8 @@ def run_applescript(script_path: str, *args) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def run_applescript_inline(script: str) -> str:
|
def run_applescript_inline(script: str) -> str:
|
||||||
"""인라인 AppleScript 실행 — 행별 -e 분할 방식"""
|
"""인라인 AppleScript 실행 — 단일 -e 방식"""
|
||||||
lines = script.strip().split('\n')
|
cmd = ["osascript", "-e", script]
|
||||||
cmd = ["osascript"]
|
|
||||||
for line in lines:
|
|
||||||
cmd.extend(["-e", line])
|
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user