diff --git a/plexpy/config.py b/plexpy/config.py index bcbf1456..8c4fab8d 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -269,9 +269,9 @@ def make_backup(cleanup=False, scheduler=False): """ Makes a backup of config file, removes all but the last 5 backups """ if scheduler: - backup_file = 'config.backup-{}.sched.ini'.format(helpers.now(no_sep=True)) + backup_file = 'config.backup-{}.sched.ini'.format(helpers.now()) else: - backup_file = 'config.backup-{}.ini'.format(helpers.now(no_sep=True)) + backup_file = 'config.backup-{}.ini'.format(helpers.now()) backup_folder = plexpy.CONFIG.BACKUP_DIR backup_file_fp = os.path.join(backup_folder, backup_file) diff --git a/plexpy/database.py b/plexpy/database.py index 315db44a..073e4fdc 100644 --- a/plexpy/database.py +++ b/plexpy/database.py @@ -292,9 +292,9 @@ def make_backup(cleanup=False, scheduler=False): plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_plexpydbcorrupt'}) if scheduler: - backup_file = 'tautulli.backup-{}{}.sched.db'.format(helpers.now(no_sep=True), corrupt) + backup_file = 'tautulli.backup-{}{}.sched.db'.format(helpers.now(), corrupt) else: - backup_file = 'tautulli.backup-{}{}.db'.format(helpers.now(no_sep=True), corrupt) + backup_file = 'tautulli.backup-{}{}.db'.format(helpers.now(), corrupt) backup_folder = plexpy.CONFIG.BACKUP_DIR backup_file_fp = os.path.join(backup_folder, backup_file) diff --git a/plexpy/helpers.py b/plexpy/helpers.py index d6c3d3dd..67098aba 100644 --- a/plexpy/helpers.py +++ b/plexpy/helpers.py @@ -213,25 +213,25 @@ def today(): return yyyymmdd -def now(no_sep=False): - now = datetime.datetime.now() - if no_sep: - return now.strftime("%Y%m%d%H%M%S") - return now.strftime("%Y-%m-%d %H:%M:%S") - - def utc_now_iso(): utcnow = datetime.datetime.utcnow() return utcnow.isoformat() -def timestamp_to_YMD(timestamp): - return timestamp_to_datetime(timestamp).strftime("%Y-%m-%d") +def now(sep=False): + return timestamp_to_YMDHMS(timestamp(), sep=sep) -def timestamp_to_datetime(timestamp): - return datetime.datetime.fromtimestamp(cast_to_int(str(timestamp))) +def timestamp_to_YMDHMS(ts, sep=False): + dt = timestamp_to_datetime(ts) + if sep: + return dt.strftime("%Y-%m-%d %H:%M:%S") + return dt.strftime("%Y%m%d%H%M%S") + + +def timestamp_to_datetime(ts): + return datetime.datetime.fromtimestamp(ts) def iso_to_YMD(iso):