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

313 lines
17 KiB
Python

#!/usr/bin/env python3
"""
Add "Evaluate Diet" routine to Tasker project
- 21:00 (9:00 PM) notification
- Open Note button
- Mark Done button
"""
import re
def add_diet_routine(input_file, output_file):
with open(input_file, 'r', encoding='utf-8') as f:
content = f.read()
# Find the highest profile and task IDs
profile_ids = re.findall(r'<Profile sr="prof(\d+)"', content)
task_ids = re.findall(r'<Task sr="task(\d+)"', content)
max_profile_id = max([int(pid) for pid in profile_ids]) if profile_ids else 150
max_task_id = max([int(tid) for tid in task_ids]) if task_ids else 150
# New IDs
new_profile_trigger_id = max_profile_id + 1
new_profile_event_open_id = max_profile_id + 2
new_profile_event_done_id = max_profile_id + 3
new_task_show_id = max_task_id + 1
new_task_done_id = max_task_id + 2
# Check if already exists
if 'Trigger Diet Notification' in content:
print("⚠ Diet routine already exists. Skipping.")
return
# Find insertion point (before </TaskerData>)
insert_point = content.rfind('</TaskerData>')
# Profile 1: Time trigger (21:00)
profile_trigger = f'''
<!-- Diet Evaluation Routine -->
<Profile sr="prof{new_profile_trigger_id}" ve="2">
<cdate>1762631944649</cdate>
<edate>1762935025169</edate>
<flags>8</flags>
<id>{new_profile_trigger_id}</id>
<mid0>{new_task_show_id}</mid0>
<nme>Trigger Diet Notification</nme>
<Time sr="con0">
<fh>21</fh>
<fm>0</fm>
<th>21</th>
<tm>0</tm>
</Time>
</Profile>'''
# Profile 2: Event listener for "Open Diet Note" button
profile_event_open = f'''
<Profile sr="prof{new_profile_event_open_id}" ve="2">
<cdate>1762862939813</cdate>
<edate>1762935050872</edate>
<flags>8</flags>
<id>{new_profile_event_open_id}</id>
<mid0>63</mid0>
<nme>Event: Open Diet Note</nme>
<Event sr="con0" ve="2">
<code>1825107102</code>
<pri>0</pri>
<Bundle sr="arg0">
<Vals sr="val">
<com.twofortyfouram.locale.intent.extra.BLURB>Event Behaviour
Filter: cmd_open_diet_note</com.twofortyfouram.locale.intent.extra.BLURB>
<com.twofortyfouram.locale.intent.extra.BLURB-type>java.lang.String</com.twofortyfouram.locale.intent.extra.BLURB-type>
<command_params_var>anpar</command_params_var>
<command_params_var-type>java.lang.String</command_params_var-type>
<command_var>ancomm</command_var>
<command_var-type>java.lang.String</command_var-type>
<config_notification_command>cmd_open_diet_note</config_notification_command>
<config_notification_command-type>java.lang.String</config_notification_command-type>
<message_single_case_insensitive>false</message_single_case_insensitive>
<message_single_case_insensitive-type>java.lang.Boolean</message_single_case_insensitive-type>
<message_single_exact>false</message_single_exact>
<message_single_exact-type>java.lang.Boolean</message_single_exact-type>
<message_single_regex>false</message_single_regex>
<message_single_regex-type>java.lang.Boolean</message_single_regex-type>
<message_var>anmessage</message_var>
<message_var-type>java.lang.String</message_var-type>
<net.dinglisch.android.tasker.EXTRA_NSR_DEPRECATED>true</net.dinglisch.android.tasker.EXTRA_NSR_DEPRECATED>
<net.dinglisch.android.tasker.EXTRA_NSR_DEPRECATED-type>java.lang.Boolean</net.dinglisch.android.tasker.EXTRA_NSR_DEPRECATED-type>
<net.dinglisch.android.tasker.RELEVANT_VARIABLES>&lt;StringArray sr=""&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;%ancomm
Everything to the right of =:=
Everything to the right of =:=&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1&gt;%anmessage
Whole AutoNotification Message
Whole AutoNotification Message&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2&gt;%anpar()
Array of single words to the left of =:=
Array of single words to the left of =:=&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2&gt;&lt;/StringArray&gt;</net.dinglisch.android.tasker.RELEVANT_VARIABLES>
<net.dinglisch.android.tasker.RELEVANT_VARIABLES-type>[Ljava.lang.String;</net.dinglisch.android.tasker.RELEVANT_VARIABLES-type>
<net.dinglisch.android.tasker.extras.REQUESTED_TIMEOUT>10000</net.dinglisch.android.tasker.extras.REQUESTED_TIMEOUT>
<net.dinglisch.android.tasker.extras.REQUESTED_TIMEOUT-type>java.lang.Integer</net.dinglisch.android.tasker.extras.REQUESTED_TIMEOUT-type>
<net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS>message_var command_var command_params_var config_notification_command plugininstanceid plugintypeid </net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS>
<net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS-type>java.lang.String</net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS-type>
<net.dinglisch.android.tasker.subbundled>true</net.dinglisch.android.tasker.subbundled>
<net.dinglisch.android.tasker.subbundled-type>java.lang.Boolean</net.dinglisch.android.tasker.subbundled-type>
<plugininstanceid>e1a87f0a-2e17-4b02-ab14-479198b7aeb1</plugininstanceid>
<plugininstanceid-type>java.lang.String</plugininstanceid-type>
<plugintypeid>com.joaomgcd.autonotification.intent.IntentCommandEvent</plugintypeid>
<plugintypeid-type>java.lang.String</plugintypeid-type>
</Vals>
</Bundle>
<Str sr="arg1" ve="3">com.joaomgcd.autonotification</Str>
<Str sr="arg2" ve="3">com.joaomgcd.autonotification.activity.ActivityConfigConditionTaskerEvent</Str>
<Int sr="arg3" val="1"/>
</Event>
</Profile>'''
# Profile 3: Event listener for "Mark Done" button
profile_event_done = f'''
<Profile sr="prof{new_profile_event_done_id}" ve="2">
<cdate>1762934954023</cdate>
<edate>1762935062373</edate>
<flags>8</flags>
<id>{new_profile_event_done_id}</id>
<mid0>{new_task_done_id}</mid0>
<nme>Event: Mark Diet Done</nme>
<Event sr="con0" ve="2">
<code>1825107102</code>
<pri>0</pri>
<Bundle sr="arg0">
<Vals sr="val">
<com.twofortyfouram.locale.intent.extra.BLURB>Event Behaviour
Filter: cmd_mark_diet_done</com.twofortyfouram.locale.intent.extra.BLURB>
<com.twofortyfouram.locale.intent.extra.BLURB-type>java.lang.String</com.twofortyfouram.locale.intent.extra.BLURB-type>
<command_params_var>anpar</command_params_var>
<command_params_var-type>java.lang.String</command_params_var-type>
<command_var>ancomm</command_var>
<command_var-type>java.lang.String</command_var-type>
<config_notification_command>cmd_mark_diet_done</config_notification_command>
<config_notification_command-type>java.lang.String</config_notification_command-type>
<message_single_case_insensitive>false</message_single_case_insensitive>
<message_single_case_insensitive-type>java.lang.Boolean</message_single_case_insensitive-type>
<message_single_exact>false</message_single_exact>
<message_single_exact-type>java.lang.Boolean</message_single_exact-type>
<message_single_regex>false</message_single_regex>
<message_single_regex-type>java.lang.Boolean</message_single_regex-type>
<message_var>anmessage</message_var>
<message_var-type>java.lang.String</message_var-type>
<net.dinglisch.android.tasker.EXTRA_NSR_DEPRECATED>true</net.dinglisch.android.tasker.EXTRA_NSR_DEPRECATED>
<net.dinglisch.android.tasker.EXTRA_NSR_DEPRECATED-type>java.lang.Boolean</net.dinglisch.android.tasker.EXTRA_NSR_DEPRECATED-type>
<net.dinglisch.android.tasker.RELEVANT_VARIABLES>&lt;StringArray sr=""&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;%ancomm
Everything to the right of =:=
Everything to the right of =:=&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1&gt;%anmessage
Whole AutoNotification Message
Whole AutoNotification Message&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2&gt;%anpar()
Array of single words to the left of =:=
Array of single words to the left of =:=&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2&gt;&lt;/StringArray&gt;</net.dinglisch.android.tasker.RELEVANT_VARIABLES>
<net.dinglisch.android.tasker.RELEVANT_VARIABLES-type>[Ljava.lang.String;</net.dinglisch.android.tasker.RELEVANT_VARIABLES-type>
<net.dinglisch.android.tasker.extras.REQUESTED_TIMEOUT>10000</net.dinglisch.android.tasker.extras.REQUESTED_TIMEOUT>
<net.dinglisch.android.tasker.extras.REQUESTED_TIMEOUT-type>java.lang.Integer</net.dinglisch.android.tasker.extras.REQUESTED_TIMEOUT-type>
<net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS>message_var command_var command_params_var config_notification_command plugininstanceid plugintypeid </net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS>
<net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS-type>java.lang.String</net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS-type>
<net.dinglisch.android.tasker.subbundled>true</net.dinglisch.android.tasker.subbundled>
<net.dinglisch.android.tasker.subbundled-type>java.lang.Boolean</net.dinglisch.android.tasker.subbundled-type>
<plugininstanceid>6cbbccc1-1242-4f6a-861e-cfe4b82309fd</plugininstanceid>
<plugininstanceid-type>java.lang.String</plugininstanceid-type>
<plugintypeid>com.joaomgcd.autonotification.intent.IntentCommandEvent</plugintypeid>
<plugintypeid-type>java.lang.String</plugintypeid-type>
</Vals>
</Bundle>
<Str sr="arg1" ve="3">com.joaomgcd.autonotification</Str>
<Str sr="arg2" ve="3">com.joaomgcd.autonotification.activity.ActivityConfigConditionTaskerEvent</Str>
<Int sr="arg3" val="1"/>
</Event>
</Profile>'''
# Task 1: Show Diet Notification
task_show = f'''
<Task sr="task{new_task_show_id}">
<cdate>1762631971435</cdate>
<edate>1762935044696</edate>
<id>{new_task_show_id}</id>
<nme>Show Diet Notification</nme>
<pri>100</pri>
<Action sr="act0" ve="7">
<code>166160670</code>
<Bundle sr="arg0">
<Vals sr="val">
<StatusBarTextSize>16</StatusBarTextSize>
<StatusBarTextSize-type>java.lang.String</StatusBarTextSize-type>
<com.twofortyfouram.locale.intent.extra.BLURB>Title: Evaluate Your Diet
Text: Time to review your eating today!
Action on Touch: cmd_open_diet_note
Status Bar Text Size: 16
Id: notif_diet_evening
Separator: ,
Button 1: cmd_open_diet_note
Label 1: Open Note
Button 2: cmd_mark_diet_done
Label 2: Mark Done</com.twofortyfouram.locale.intent.extra.BLURB>
<com.twofortyfouram.locale.intent.extra.BLURB-type>java.lang.String</com.twofortyfouram.locale.intent.extra.BLURB-type>
<config_notification_action>cmd_open_diet_note</config_notification_action>
<config_notification_action-type>java.lang.String</config_notification_action-type>
<config_notification_action_button1>cmd_open_diet_note</config_notification_action_button1>
<config_notification_action_button1-type>java.lang.String</config_notification_action_button1-type>
<config_notification_action_button2>cmd_mark_diet_done</config_notification_action_button2>
<config_notification_action_button2-type>java.lang.String</config_notification_action_button2-type>
<config_notification_action_label1>Open Note</config_notification_action_label1>
<config_notification_action_label1-type>java.lang.String</config_notification_action_label1-type>
<config_notification_action_label2>Mark Done</config_notification_action_label2>
<config_notification_action_label2-type>java.lang.String</config_notification_action_label2-type>
<config_notification_dismiss_on_touch>false</config_notification_dismiss_on_touch>
<config_notification_dismiss_on_touch-type>java.lang.Boolean</config_notification_dismiss_on_touch-type>
<config_notification_persistent>false</config_notification_persistent>
<config_notification_persistent-type>java.lang.Boolean</config_notification_persistent-type>
<config_notification_text>Time to review your eating today!</config_notification_text>
<config_notification_text-type>java.lang.String</config_notification_text-type>
<config_notification_title>Evaluate Your Diet</config_notification_title>
<config_notification_title-type>java.lang.String</config_notification_title-type>
<net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS>StatusBarTextSize config_notification_title config_notification_text config_notification_action config_notification_action_button1 config_notification_action_label1 config_notification_action_button2 config_notification_action_label2 notificaitionid plugininstanceid plugintypeid </net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS>
<net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS-type>java.lang.String</net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS-type>
<net.dinglisch.android.tasker.subbundled>true</net.dinglisch.android.tasker.subbundled>
<net.dinglisch.android.tasker.subbundled-type>java.lang.Boolean</net.dinglisch.android.tasker.subbundled-type>
<notificaitionid>notif_diet_evening</notificaitionid>
<notificaitionid-type>java.lang.String</notificaitionid-type>
<plugininstanceid>2c3b7c1e-0ee9-4d73-bf77-2b1311cf1a26</plugininstanceid>
<plugininstanceid-type>java.lang.String</plugininstanceid-type>
<plugintypeid>com.joaomgcd.autonotification.intent.IntentNotification</plugintypeid>
<plugintypeid-type>java.lang.String</plugintypeid-type>
</Vals>
</Bundle>
<Str sr="arg1" ve="3">com.joaomgcd.autonotification</Str>
<Str sr="arg2" ve="3">com.joaomgcd.autonotification.activity.ActivityConfigNotify</Str>
<Int sr="arg3" val="20"/>
<Int sr="arg4" val="1"/>
</Action>
</Task>'''
# Task 2: Mark Diet Done (dismiss notification)
task_done = f'''
<Task sr="task{new_task_done_id}">
<cdate>1762934967274</cdate>
<edate>1762935062373</edate>
<id>{new_task_done_id}</id>
<nme>Mark Diet Done</nme>
<pri>6</pri>
<Action sr="act0" ve="7">
<code>2046367074</code>
<Bundle sr="arg0">
<Vals sr="val">
<App>&lt;null&gt;</App>
<App-type>java.lang.String</App-type>
<CancelAll>false</CancelAll>
<CancelAll-type>java.lang.Boolean</CancelAll-type>
<CancelPersistent>false</CancelPersistent>
<CancelPersistent-type>java.lang.Boolean</CancelPersistent-type>
<com.twofortyfouram.locale.intent.extra.BLURB>Id: notif_diet_evening</com.twofortyfouram.locale.intent.extra.BLURB>
<com.twofortyfouram.locale.intent.extra.BLURB-type>java.lang.String</com.twofortyfouram.locale.intent.extra.BLURB-type>
<net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS>notificaitionid plugininstanceid plugintypeid </net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS>
<net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS-type>java.lang.String</net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS-type>
<net.dinglisch.android.tasker.subbundled>true</net.dinglisch.android.tasker.subbundled>
<net.dinglisch.android.tasker.subbundled-type>java.lang.Boolean</net.dinglisch.android.tasker.subbundled-type>
<notificaitionid>notif_diet_evening</notificaitionid>
<notificaitionid-type>java.lang.String</notificaitionid-type>
<plugininstanceid>2d6b7e1a-427b-442e-9f39-356480bf35d3</plugininstanceid>
<plugininstanceid-type>java.lang.String</plugininstanceid-type>
<plugintypeid>com.joaomgcd.autonotification.intent.IntentCancelNotification</plugintypeid>
<plugintypeid-type>java.lang.String</plugintypeid-type>
</Vals>
</Bundle>
<Str sr="arg1" ve="3">com.joaomgcd.autonotification</Str>
<Str sr="arg2" ve="3">com.joaomgcd.autonotification.activity.ActivityConfigCancelNotification</Str>
<Int sr="arg3" val="20"/>
<Int sr="arg4" val="1"/>
</Action>
</Task>'''
# Combine all new elements
new_elements = profile_trigger + profile_event_open + profile_event_done + task_show + task_done
# Insert before </TaskerData>
content = content[:insert_point] + new_elements + '\n' + content[insert_point:]
# Update project pids (profile IDs)
content = re.sub(
r'<pids>([^<]+)</pids>',
lambda m: f'<pids>{m.group(1)},{new_profile_trigger_id},{new_profile_event_open_id},{new_profile_event_done_id}</pids>',
content,
count=1
)
# Update project tids (task IDs)
content = re.sub(
r'<tids>([^<]+)</tids>',
lambda m: f'<tids>{m.group(1)},{new_task_show_id},{new_task_done_id}</pids>',
content,
count=1
)
# Write output
with open(output_file, 'w', encoding='utf-8') as f:
f.write(content)
print(f"✓ Added 'Evaluate Diet' routine")
print(f" - Trigger time: 21:00 (9:00 PM)")
print(f" - Profile IDs: {new_profile_trigger_id}, {new_profile_event_open_id}, {new_profile_event_done_id}")
print(f" - Task IDs: {new_task_show_id}, {new_task_done_id}")
print(f" - Commands: cmd_open_diet_note, cmd_mark_diet_done")
print(f" - Notification ID: notif_diet_evening")
print(f"✓ Output written to {output_file}")
if __name__ == '__main__':
input_file = '/Users/vincentverbruggen/Personal/Personal/Areas/Tasker/Routine_Reminders.prj.xml'
output_file = '/Users/vincentverbruggen/Personal/Personal/Areas/Tasker/Routine_Reminders.prj.xml'
add_diet_routine(input_file, output_file)