From 092d858b12a944a28a3e88cea3e5a10e43c941b2 Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Sat, 5 Jun 2021 08:54:13 -0700 Subject: [PATCH] Update library and user watch time query to match homepage --- plexpy/libraries.py | 6 ++++-- plexpy/users.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plexpy/libraries.py b/plexpy/libraries.py index ad4e9bd2..af66cfc7 100644 --- a/plexpy/libraries.py +++ b/plexpy/libraries.py @@ -902,6 +902,8 @@ class Libraries(object): else: query_days = [1, 7, 30, 0] + timestamp = helpers.timestamp() + monitor_db = database.MonitorDatabase() library_watch_time_stats = [] @@ -909,7 +911,7 @@ class Libraries(object): group_by = 'session_history.reference_id' if grouping else 'session_history.id' for days in query_days: - timestamp = int((datetime.now(tz=plexpy.SYS_TIMEZONE) - timedelta(days=days)).timestamp()) + timestamp_query = timestamp - days * 24 * 60 * 60 try: if days > 0: @@ -920,7 +922,7 @@ class Libraries(object): 'FROM session_history ' \ 'JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \ 'WHERE stopped >= %s ' \ - 'AND section_id = ?' % (group_by, timestamp) + 'AND section_id = ?' % (group_by, timestamp_query) result = monitor_db.select(query, args=[section_id]) else: result = [] diff --git a/plexpy/users.py b/plexpy/users.py index d3e5103e..480dee3d 100644 --- a/plexpy/users.py +++ b/plexpy/users.py @@ -494,6 +494,8 @@ class Users(object): else: query_days = [1, 7, 30, 0] + timestamp = helpers.timestamp() + monitor_db = database.MonitorDatabase() user_watch_time_stats = [] @@ -501,7 +503,7 @@ class Users(object): group_by = 'reference_id' if grouping else 'id' for days in query_days: - timestamp = int((datetime.now(tz=plexpy.SYS_TIMEZONE) - timedelta(days=days)).timestamp()) + timestamp_query = timestamp - days * 24 * 60 * 60 try: if days > 0: @@ -511,7 +513,7 @@ class Users(object): 'COUNT(DISTINCT %s) AS total_plays ' \ 'FROM session_history ' \ 'WHERE stopped >= %s ' \ - 'AND user_id = ? ' % (group_by, timestamp) + 'AND user_id = ? ' % (group_by, timestamp_query) result = monitor_db.select(query, args=[user_id]) else: result = []