Skip to content

Commit

Permalink
Added feature to only edit, not delete reddit items (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Gottschlich authored Mar 21, 2019
1 parent 09cbc65 commit 56f9466
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
23 changes: 19 additions & 4 deletions SocialAmnesia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:')
Expand Down Expand Up @@ -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')

Expand Down
19 changes: 16 additions & 3 deletions services/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand Down Expand Up @@ -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.')
Expand Down

0 comments on commit 56f9466

Please sign in to comment.