Users's inactive days is now configurable during setup
This commit is contained in:
pare
8637160b53
commit
05f097a048
S'han modificat 2 arxius amb 11 adicions i 5 eliminacions
|
@ -17,6 +17,7 @@ def get_config():
|
||||||
mailing_db = get_parameter("mailing_db", config_filepath)
|
mailing_db = get_parameter("mailing_db", config_filepath)
|
||||||
mailing_db_user = get_parameter("mailing_db_user", config_filepath)
|
mailing_db_user = get_parameter("mailing_db_user", config_filepath)
|
||||||
mailing_db_table = get_parameter("mailing_db_table", config_filepath)
|
mailing_db_table = get_parameter("mailing_db_table", config_filepath)
|
||||||
|
inactive_days = get_parameter("inactive_days", config_filepath)
|
||||||
|
|
||||||
return (mastodon_db, mastodon_db_user, mailing_db, mailing_db_user, mailing_db_table)
|
return (mastodon_db, mastodon_db_user, mailing_db, mailing_db_user, mailing_db_table)
|
||||||
|
|
||||||
|
@ -49,12 +50,15 @@ def write_parameter( parameter, file_path ):
|
||||||
mailing_db = input("Mailing db name: ")
|
mailing_db = input("Mailing db name: ")
|
||||||
mailing_db_user = input("Mailing db user: ")
|
mailing_db_user = input("Mailing db user: ")
|
||||||
mailing_db_table = input("Mailing db table: ")
|
mailing_db_table = input("Mailing db table: ")
|
||||||
|
inactive_days = input("Inactive days: ")
|
||||||
|
|
||||||
with open(file_path, "w") as text_file:
|
with open(file_path, "w") as text_file:
|
||||||
print("mastodon_db: {}".format(mastodon_db), file=text_file)
|
print("mastodon_db: {}".format(mastodon_db), file=text_file)
|
||||||
print("mastodon_db_user: {}".format(mastodon_db_user), file=text_file)
|
print("mastodon_db_user: {}".format(mastodon_db_user), file=text_file)
|
||||||
print("mailing_db: {}".format(mailing_db), file=text_file)
|
print("mailing_db: {}".format(mailing_db), file=text_file)
|
||||||
print("mailing_db_user: {}".format(mailing_db_user), file=text_file)
|
print("mailing_db_user: {}".format(mailing_db_user), file=text_file)
|
||||||
print("mailing_db_table: {}".format(mailing_db_table), file=text_file)
|
print("mailing_db_table: {}".format(mailing_db_table), file=text_file)
|
||||||
|
print("inactive_days: {}".format(inactive_days), file=text_file)
|
||||||
|
|
||||||
def create_database():
|
def create_database():
|
||||||
|
|
||||||
|
@ -94,7 +98,7 @@ def create_database():
|
||||||
|
|
||||||
print(error)
|
print(error)
|
||||||
# Load configuration from config file
|
# Load configuration from config file
|
||||||
os.remove("config.txt")
|
os.remove("config/db_config.txt")
|
||||||
print("Exiting. Run setup again with right parameters")
|
print("Exiting. Run setup again with right parameters")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
10
inactives.py
10
inactives.py
|
@ -28,8 +28,9 @@ def db_config():
|
||||||
mailing_db = get_parameter("mailing_db", config_filepath)
|
mailing_db = get_parameter("mailing_db", config_filepath)
|
||||||
mailing_db_user = get_parameter("mailing_db_user", config_filepath)
|
mailing_db_user = get_parameter("mailing_db_user", config_filepath)
|
||||||
mailing_db_table = get_parameter("mailing_db_table", config_filepath)
|
mailing_db_table = get_parameter("mailing_db_table", config_filepath)
|
||||||
|
inactive_days = get_parameter("inactive_days", config_filepath)
|
||||||
|
|
||||||
return (mastodon_db, mastodon_db_user, mailing_db, mailing_db_user, mailing_db_table)
|
return (mastodon_db, mastodon_db_user, mailing_db, mailing_db_user, mailing_db_table, inactive_days)
|
||||||
|
|
||||||
def get_parameter( parameter, file_path ):
|
def get_parameter( parameter, file_path ):
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ class Inactives:
|
||||||
|
|
||||||
smtp_host, smtp_user_login, smtp_user_password, email_subject = smtp_config()
|
smtp_host, smtp_user_login, smtp_user_password, email_subject = smtp_config()
|
||||||
|
|
||||||
mastodon_db, mastodon_db_user, mailing_db, mailing_db_user, mailing_db_table = db_config()
|
mastodon_db, mastodon_db_user, mailing_db, mailing_db_user, mailing_db_table, inactive_days = db_config()
|
||||||
|
|
||||||
self.smtp_host = smtp_host
|
self.smtp_host = smtp_host
|
||||||
self.smtp_user_login = smtp_user_login
|
self.smtp_user_login = smtp_user_login
|
||||||
|
@ -71,6 +72,7 @@ class Inactives:
|
||||||
self.mailing_db = mailing_db
|
self.mailing_db = mailing_db
|
||||||
self.mailing_db_user = mailing_db_user
|
self.mailing_db_user = mailing_db_user
|
||||||
self.mailing_db_table = mailing_db_table
|
self.mailing_db_table = mailing_db_table
|
||||||
|
self.inactive_days = inactive_days
|
||||||
self.now = datetime.now(timezone.utc)
|
self.now = datetime.now(timezone.utc)
|
||||||
|
|
||||||
def id(self):
|
def id(self):
|
||||||
|
@ -144,7 +146,7 @@ class Inactives:
|
||||||
|
|
||||||
reactivated = email_datetime < seen
|
reactivated = email_datetime < seen
|
||||||
|
|
||||||
last_year = datetime.today() - timedelta(days=180)
|
last_year = datetime.today() - timedelta(days=int(self.inactive_days))
|
||||||
|
|
||||||
if reactivated == True or seen == None or seen > last_year: #if inactive user had reactivated its account or had deleted it we must delete related row from 'mailing_db_table'
|
if reactivated == True or seen == None or seen > last_year: #if inactive user had reactivated its account or had deleted it we must delete related row from 'mailing_db_table'
|
||||||
|
|
||||||
|
@ -182,7 +184,7 @@ class Inactives:
|
||||||
|
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
|
|
||||||
cur.execute("select account_id, email, current_sign_in_at from users where current_sign_in_at < now() - interval '180 days' and disabled=False and approved=True order by current_sign_in_at desc")
|
cur.execute("select account_id, email, current_sign_in_at from users where current_sign_in_at < now() - interval '" + self.inactive_days + " days' and disabled=False and approved=True order by current_sign_in_at desc")
|
||||||
|
|
||||||
rows = cur.fetchall()
|
rows = cur.fetchall()
|
||||||
|
|
||||||
|
|
Loading…
Referencia en una nova incidència