From f7836b1faece7f26558e78584d1386c8c2211a1c Mon Sep 17 00:00:00 2001 From: spla Date: Sun, 5 Jul 2020 20:43:04 +0200 Subject: [PATCH] Delete no feedback inactive users. Fix #4 --- delete_inactives.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/delete_inactives.py b/delete_inactives.py index 0686548..a814025 100644 --- a/delete_inactives.py +++ b/delete_inactives.py @@ -9,7 +9,7 @@ import sys import os.path import psycopg2 -def delete_inactives(mailing_db, mailing_db_user, mailing_db_table, query, id_array, username_array): +def delete_inactives(mailing_db, mailing_db_user, mailing_db_table, deletion_accepted, query, id_array, username_array): conn = None @@ -19,7 +19,6 @@ def delete_inactives(mailing_db, mailing_db_user, mailing_db_table, query, id_ar cur = conn.cursor() - # executem SELECT cur.execute(query) for row in cur: @@ -29,10 +28,19 @@ def delete_inactives(mailing_db, mailing_db_user, mailing_db_table, query, id_ar i = 0 if len(id_array) == 0: - sys.exit("None inactive users found!") + if deletion_accepted == True: + print("None inactive users who accepted to be deleted found!") + elif deletion_accepted == False: + print("None inactive users to be deleted!") + return while i < len(id_array): + if deletion_accepted == True: + print("Deleting inactive users who accepted to be deleted...") + elif deletion_accepted == False: + print("Deleting inactive users who do not reply our email...") + print("\n") print("Deleting user " + str(i) + " of " + str(len(id_array)) + " users") print("Deleting user with id " + str(id_array[i]) + ", username: " + username_array[i]) @@ -127,16 +135,18 @@ rvm_ruby = os.environ['HOME'] + "/.rbenv/shims/ruby" # select users who replied the warning email saying yes to deletion ############################################################################### +deletion_accepted = True query = "select account_id, username, email, to_be_deleted, feedback, recipient_error, elapsed_days from " + mailing_db_table + " where to_be_deleted = 't' and feedback = 't' and recipient_error = 'f' and emailed_at < now() - interval '31 days'" id_array = [] username_array = [] -delete_inactives(mailing_db, mailing_db_user, mailing_db_table, query, id_array, username_array) +delete_inactives(mailing_db, mailing_db_user, mailing_db_table, deletion_accepted, query, id_array, username_array) ############################################################################### # select users who don't replied to email after 30 days ############################################################################### +deletion_accepted = False query = "select account_id, username, email, to_be_deleted, feedback, recipient_error, elapsed_days from inactive_users where to_be_deleted = 'f' and feedback = 'f' and recipient_error = 'f' and emailed_at < now() - interval '31 days'" id_array = [] username_array = [] -delete_inactives(mailing_db, mailing_db_user, mailing_db_table, query, id_array, username_array) +delete_inactives(mailing_db, mailing_db_user, mailing_db_table, deletion_accepted, query, id_array, username_array)