diff --git a/cleanserver.py b/cleanserver.py index 6682f9c..9870d82 100644 --- a/cleanserver.py +++ b/cleanserver.py @@ -64,7 +64,7 @@ def dead(): cur = conn.cursor() - cur.execute("select server from peers where downs >= '7'") + cur.execute("select server from peers where downs >=(%s)", (purge_days,)) rows = cur.fetchall() @@ -280,6 +280,7 @@ if __name__ == '__main__': config_filepath = "config/config.txt" mastodon_hostname = get_parameter("mastodon_hostname", config_filepath) mastodon_full_path = get_parameter("mastodon_full_path", config_filepath) + purge_days = get_parameter("purge_days", config_filepath) cleanserver_db, cleanserver_db_user = dbconfig() diff --git a/setup.py b/setup.py index cdc6afc..dbf31f0 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,8 @@ def write_config(): print(f"adding parameter 'mastodon_hostname' to {config_filepath}") the_file.write('mastodon_full_path: \n') print(f"adding parameter 'mastodon_full_path' to {config_filepath}") + the_file.write('purge_days: \n') + print(f"adding parameter 'purge_days' to {config_filepath}") def read_config_line(): @@ -28,6 +30,7 @@ def read_config_line(): line = fp.readline() modify_file(config_filepath, "mastodon_hostname: ", value=hostname) modify_file(config_filepath, "mastodon_full_path: ", value=full_path) + modify_file(config_filepath, "purge_days: ", value=purge_days) def modify_file(file_name,pattern,value=""): @@ -63,10 +66,12 @@ def get_parameter( parameter, config_filepath ): write_config() - global hostname, full_path + global hostname, full_path, purge_days hostname = input("Enter Mastodon hostname: ") full_path = input("Enter Mastodon's full path dir: ") + purge_days = int(input("Enter days to trigger server purge (default 7): ") or "7") + purge_days = str(purge_days) read_config_line() @@ -82,3 +87,4 @@ if __name__ == '__main__': config_filepath = "config/config.txt" mastodon_hostname = get_parameter("mastodon_hostname", config_filepath) mastodon_full_path = get_parameter("mastodon_full_path", config_filepath) + purge_days = get_parameter("purge_days", config_filepath)