Skip to content

Commit

Permalink
Added option to edit reddit items multiple times (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Gottschlich authored Mar 20, 2019
1 parent 0cfdbde commit 09cbc65
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
25 changes: 20 additions & 5 deletions SocialAmnesia.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def handle_callback_error(*args):
messagebox.showerror('Error', keyErrorString)
else:
messagebox.showerror('Error', errors.get(
received_error, received_error))
received_error, received_error))

def build_login_tab(self):
"""
Expand Down Expand Up @@ -373,6 +373,18 @@ def get_text(time, text):
configuration_frame, variable=gilded_skip_bool,
command=lambda: reddit.set_reddit_gilded_skip(gilded_skip_bool, reddit_state))

# Multiple edits
multi_edit_bool = tk.IntVar()
if 'multi_edit' in reddit_state:
if reddit_state['multi_edit'] == 0:
multi_edit_bool.set(0)
else:
multi_edit_bool.set(1)
multi_edit_label = tk.Label(
configuration_frame, text='Edit item multiple times before deleting (runs slightly slower):')
multi_edit_check_button = tk.Checkbutton(
configuration_frame, variable=multi_edit_bool, command=lambda: reddit.set_multi_edit(multi_edit_bool, reddit_state))

# White listing
whitelist_label = tk.Label(
configuration_frame, text='Whitelist comments or submissions:')
Expand Down Expand Up @@ -470,14 +482,17 @@ def get_text(time, text):
gilded_skip_label.grid(row=3, column=0, sticky='w')
gilded_skip_check_button.grid(row=3, column=1, sticky='w')

whitelist_label.grid(row=4, column=0, sticky='w')
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')
modify_whitelist_comments_button.grid(
row=4, column=1, columnspan=4, sticky='w')
row=5, column=1, columnspan=4, sticky='w')
modify_whitelist_posts_button.grid(
row=4, column=5, columnspan=4, sticky='w')
row=5, column=5, columnspan=4, sticky='w')

ttk.Separator(configuration_frame, orient=tk.HORIZONTAL).grid(
row=5, columnspan=13, sticky='ew', pady=5)
row=6, columnspan=13, sticky='ew', pady=5)

deletion_section_label.grid(row=0, column=0, sticky='w')

Expand Down
32 changes: 28 additions & 4 deletions services/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sys
import random
import socket
import string
sys.path.insert(0, "../utils")

USER_AGENT = 'Social Amnesia (by /u/JavaOffScript)'
Expand Down Expand Up @@ -79,6 +80,7 @@ def initialize_state(reddit_state):
arrow.now().replace(hours=0))
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('whitelisted_comments', reddit_state, {})
check_for_existence('whitelisted_posts', reddit_state, {})
check_for_existence('scheduled_time', reddit_state, 0)
Expand Down Expand Up @@ -190,11 +192,11 @@ def send_message(client, message):
data = client.recv(1024).decode('utf-8')
param_tokens = data.split(' ', 2)[1].split('?', 1)[1].split('&')
params = {key: value for (key, value) in [token.split('=')
for token in param_tokens]}
for token in param_tokens]}

if state != params['state']:
send_message(client, 'State mismatch. Expected: {} Received: {}'
.format(state, params['state']))
.format(state, params['state']))
return 1
elif 'error' in params:
send_message(client, params['error'])
Expand Down Expand Up @@ -224,6 +226,7 @@ def send_message(client, message):
else:
login_confirm_text.set(f'Failed to login!')


def set_reddit_time_to_save(hours_to_save, days_to_save, weeks_to_save, years_to_save, current_time_to_save, reddit_state):
"""
See set_time_to_save function in utils/helpers.py
Expand All @@ -250,14 +253,25 @@ def set_reddit_max_score(max_score, current_max_score, reddit_state):
def set_reddit_gilded_skip(gilded_skip_bool, reddit_state):
"""
Set whether to skip gilded comments or not
:param gildedSkipBool: false to delete gilded comments, true to skip gilded comments
:param gilded_skip_bool: false to delete gilded comments, true to skip gilded comments
:param reddit_state: dictionary holding reddit settings
:return: none
"""
reddit_state['gilded_skip'] = gilded_skip_bool.get()
reddit_state.sync


def set_multi_edit(multi_edit_bool, reddit_state):
"""
Set whether to overwrite a comment with an edit multiple times
:param multi_edit_bool: false to only overwrite once, true to overwrite multiple times
:param reddit_state: dict holding reddit settings
:return: none
"""
reddit_state['multi_edit'] = multi_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 Down Expand Up @@ -339,7 +353,17 @@ def delete_items():
# Need the try/except here as it will crash on
# link submissions otherwise
try:
item.edit(EDIT_OVERWRITE)
if reddit_state['multi_edit']:
times = random.randint(5, 10)

for i in range(0, times):
allchar = string.ascii_letters + string.punctuation + string.digits
gibberish = "".join(random.choice(allchar)
for x in range(random.randint(50, 200)))

item.edit(gibberish)
else:
item.edit(EDIT_OVERWRITE)
except:
pass

Expand Down

0 comments on commit 09cbc65

Please sign in to comment.