Files
Obsidian-Vault/Personal/Areas/Tasker/standardize_tasker.py

152 lines
5.3 KiB
Python

#!/usr/bin/env python3
"""
Standardize Tasker XML project file
- Consistent naming conventions
- Link notification buttons to correct tasks via AutoNotification commands
- Remove trailing spaces and inconsistencies
"""
import re
import sys
def standardize_tasker_xml(input_file, output_file):
with open(input_file, 'r', encoding='utf-8') as f:
content = f.read()
# Standardize Profile names
profile_replacements = {
'Launch Skincare Notification': 'Trigger Skincare Notification',
'Launch Prepare For Exercise Notification': 'Trigger Exercise Notification',
'Open Skincare Notification': 'Show Skincare Notification',
'Open Prepare Exercise Notification': 'Show Exercise Notification',
'Dismiss Exercise Notification': 'Mark Exercise Done',
}
for old, new in profile_replacements.items():
content = content.replace(f'<nme>{old}</nme>', f'<nme>{new}</nme>')
# Standardize command names (used in AutoNotification event filters and button actions)
command_replacements = {
'Open morning skincare': 'cmd_open_skincare_note',
'open skincare note': 'cmd_open_skincare_note',
'mark skincare done': 'cmd_mark_skincare_done',
'open exercise note': 'cmd_open_exercise_note',
'mark exercise done': 'cmd_mark_exercise_done',
'open diet note': 'cmd_open_diet_note',
}
for old, new in command_replacements.items():
# Remove trailing spaces from old commands
old_variants = [old, old + ' ', old + ' ']
for variant in old_variants:
# Replace in command filters
content = content.replace(
f'<config_notification_command>{variant}</config_notification_command>',
f'<config_notification_command>{new}</config_notification_command>'
)
# Replace in button actions
content = content.replace(
f'<config_notification_action_button1>{variant}</config_notification_action_button1>',
f'<config_notification_action_button1>{new}</config_notification_action_button1>'
)
content = content.replace(
f'<config_notification_action_button2>{variant}</config_notification_action_button2>',
f'<config_notification_action_button2>{new}</config_notification_action_button2>'
)
content = content.replace(
f'<config_notification_action>{variant}</config_notification_action>',
f'<config_notification_action>{new}</config_notification_action>'
)
# Standardize notification IDs
notif_id_replacements = {
'skincare morning': 'notif_skincare_morning',
'skincare morning ': 'notif_skincare_morning',
'prepare for exercise': 'notif_exercise_prep',
}
for old, new in notif_id_replacements.items():
content = content.replace(
f'<notificaitionid>{old}</notificaitionid>',
f'<notificaitionid>{new}</notificaitionid>'
)
# Also update in BLURB text
content = re.sub(
f'Id: {re.escape(old)}([\\n<])',
f'Id: {new}\\1',
content
)
# Standardize notification titles and texts (remove trailing spaces)
content = re.sub(
r'<config_notification_title>([^<]+?) +</config_notification_title>',
r'<config_notification_title>\1</config_notification_title>',
content
)
content = re.sub(
r'<config_notification_text>([^<]+?) +</config_notification_text>',
r'<config_notification_text>\1</config_notification_text>',
content
)
# Update project name
content = content.replace(
'<name>Skincare Demo</name>',
'<name>Routine Reminders</name>'
)
# Fix BLURB descriptions to reflect standardized commands
content = re.sub(
r'Filter: mark skincare done[ ]*',
'Filter: cmd_mark_skincare_done',
content
)
content = re.sub(
r'Filter: mark exercise done[ ]*',
'Filter: cmd_mark_exercise_done',
content
)
content = re.sub(
r'Button 1: open skincare note',
'Button 1: cmd_open_skincare_note',
content
)
content = re.sub(
r'Button 2: mark skincare done',
'Button 2: cmd_mark_skincare_done',
content
)
content = re.sub(
r'Button 1: open exercise note',
'Button 1: cmd_open_exercise_note',
content
)
content = re.sub(
r'Button 2: mark exercise done',
'Button 2: cmd_mark_exercise_done',
content
)
content = re.sub(
r'Button 1: open diet note',
'Button 1: cmd_open_diet_note',
content
)
content = re.sub(
r'Action on Touch: Open morning skincare[ ]*',
'Action on Touch: cmd_open_skincare_note',
content
)
# Write output
with open(output_file, 'w', encoding='utf-8') as f:
f.write(content)
print(f"✓ Standardized {input_file}")
print(f"✓ Output written to {output_file}")
if __name__ == '__main__':
input_file = '/Users/vincentverbruggen/Personal/Personal/Areas/Tasker/Skincare_Demo_Standardized.prj.xml'
output_file = '/Users/vincentverbruggen/Personal/Personal/Areas/Tasker/Routine_Reminders.prj.xml'
standardize_tasker_xml(input_file, output_file)