fix autoremover #4
parent
4e5bbaefb8
commit
055a734096
|
@ -5,7 +5,7 @@ import pterodactylReader, fileDownloader, datetime, discordPoster, time, oldRemo
|
|||
conf = get_config()
|
||||
api_client = pterodactylReader.init_client(config=conf)
|
||||
today_date = datetime.datetime.now()
|
||||
|
||||
"""
|
||||
backups_dict = pterodactylReader.get_backups_list(api_client=api_client, server_id=conf.server_id)
|
||||
backup_uuid = pterodactylReader.get_last_backup_id(backups_dict)
|
||||
backup_url = pterodactylReader.get_backup_url(api_client=api_client, server_id=conf.server_id, backup_id=backup_uuid)
|
||||
|
@ -14,6 +14,6 @@ backup_local_path = fileDownloader.create_dirs_and_download(backup_url=backup_ur
|
|||
|
||||
if conf.discord_enabled == 1:
|
||||
discordPoster.send_url_to_discord(webhook_url=conf.discord_webhook, backup_url=f"{conf.main_domain}{backup_local_path}", datetim=today_date, backup_name=conf.discord_backupname)
|
||||
|
||||
"""
|
||||
if conf.backups_keep_days != 0:
|
||||
oldRemover.remove_old_files(today_date=today_date, keep_days=conf.backups_keep_days, root_path=conf.save_dir)
|
|
@ -15,10 +15,12 @@ def file_path_creator(date: datetime.datetime, default_path: str) -> str:
|
|||
def remove_old_files(today_date: datetime.datetime, keep_days: int, root_path: str):
|
||||
older_date = today_date - datetime.timedelta(days=keep_days)
|
||||
last_date = today_date - datetime.timedelta(days=keep_days)
|
||||
print(today_date)
|
||||
print(older_date)
|
||||
|
||||
while older_date > (datetime.datetime.now() - datetime.timedelta(days=10 + keep_days)):
|
||||
older_date = older_date - datetime.timedelta(days=1)
|
||||
|
||||
print(older_date)
|
||||
if last_date.year > older_date.year and Path(folder_path_year_creator(date=older_date, default_path=root_path)).exists():
|
||||
shutil.rmtree(folder_path_year_creator(date=older_date, default_path=root_path))
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue