From 56f946611e501a072e7549d0fbcd9a376f1646ea Mon Sep 17 00:00:00 2001 From: Nick Gottschlich Date: Wed, 20 Mar 2019 21:02:58 -0500 Subject: [PATCH] Added feature to only edit, not delete reddit items (#46) --- SocialAmnesia.py | 23 +++++++++++++++++++---- services/reddit.py | 19 ++++++++++++++++--- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/SocialAmnesia.py b/SocialAmnesia.py index 555f5dd..64cc222 100644 --- a/SocialAmnesia.py +++ b/SocialAmnesia.py @@ -385,6 +385,18 @@ def get_text(time, text): multi_edit_check_button = tk.Checkbutton( configuration_frame, variable=multi_edit_bool, command=lambda: reddit.set_multi_edit(multi_edit_bool, reddit_state)) + # Don't delete comments, only edit + only_edit_bool = tk.IntVar() + if 'only_edit' in reddit_state: + if reddit_state['only_edit'] == 0: + only_edit_bool.set(0) + else: + only_edit_bool.set(1) + only_edit_label = tk.Label( + configuration_frame, text='Only edit items, do not delete:') + only_edit_check_button = tk.Checkbutton( + configuration_frame, variable=only_edit_bool, command=lambda: reddit.set_only_edit(only_edit_bool, reddit_state)) + # White listing whitelist_label = tk.Label( configuration_frame, text='Whitelist comments or submissions:') @@ -485,14 +497,17 @@ def get_text(time, text): multi_edit_label.grid(row=4, column=0, sticky='w') multi_edit_check_button.grid(row=4, column=1, sticky='w') - whitelist_label.grid(row=5, column=0, sticky='w') + only_edit_label.grid(row=5, column=0, sticky='w') + only_edit_check_button.grid(row=5, column=1, sticky='w') + + whitelist_label.grid(row=6, column=0, sticky='w') modify_whitelist_comments_button.grid( - row=5, column=1, columnspan=4, sticky='w') + row=6, column=1, columnspan=4, sticky='w') modify_whitelist_posts_button.grid( - row=5, column=5, columnspan=4, sticky='w') + row=6, column=5, columnspan=4, sticky='w') ttk.Separator(configuration_frame, orient=tk.HORIZONTAL).grid( - row=6, columnspan=13, sticky='ew', pady=5) + row=7, columnspan=13, sticky='ew', pady=5) deletion_section_label.grid(row=0, column=0, sticky='w') diff --git a/services/reddit.py b/services/reddit.py index 4fb48c1..326e011 100644 --- a/services/reddit.py +++ b/services/reddit.py @@ -81,6 +81,7 @@ def initialize_state(reddit_state): check_for_existence('max_score', reddit_state, 0) check_for_existence('gilded_skip', reddit_state, 0) check_for_existence('multi_edit', reddit_state, 0) + check_for_existence('only_edit', reddit_state, 0) check_for_existence('whitelisted_comments', reddit_state, {}) check_for_existence('whitelisted_posts', reddit_state, {}) check_for_existence('scheduled_time', reddit_state, 0) @@ -272,6 +273,17 @@ def set_multi_edit(multi_edit_bool, reddit_state): reddit_state.sync +def set_only_edit(only_edit_bool, reddit_state): + """ + Set whether to only edit an item instead of deleting it + :param only_edit_bool: true to only edit, false to edit and delete + :param reddit_state: dict holding reddit settings + :return: none + """ + reddit_state['only_edit'] = only_edit_bool.get() + reddit_state.sync + + def delete_reddit_items(root, comment_bool, currently_deleting_text, deletion_progress_bar, num_deleted_items_text, reddit_state, scheduled_bool): """ Deletes the items according to user configurations. @@ -295,7 +307,7 @@ def delete_reddit_items(root, comment_bool, currently_deleting_text, deletion_pr 'WM_DELETE_WINDOW', lambda: close_window(confirmation_window, reddit_state, 'confirmation_window_open')) frame = build_window(root, confirmation_window, - f"The following {'comments' if comment_bool else 'posts'} will be deleted") + f"The following {'comments' if comment_bool else 'posts'} will be deleted/edited") if comment_bool: total_items = sum( @@ -367,10 +379,11 @@ def delete_items(): except: pass - item.delete() + if not reddit_state['only_edit']: + item.delete() currently_deleting_text.set( - f'Deleting {item_string} `{item_snippet}`') + f'Editing/Deleting {item_string} `{item_snippet}`') num_deleted_items_text.set( f'{str(count)}/{str(total_items)} items processed.')