Skip to content
Permalink
Browse files

Added feature to only edit, not delete reddit items (#46)

  • Loading branch information...
Nick-Gottschlich committed Mar 21, 2019
1 parent 09cbc65 commit 56f946611e501a072e7549d0fbcd9a376f1646ea
Showing with 35 additions and 7 deletions.
  1. +19 −4 SocialAmnesia.py
  2. +16 −3 services/reddit.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')

@@ -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.')

0 comments on commit 56f9466

Please sign in to comment.
You can’t perform that action at this time.