Skip to content

Commit

Permalink
Fix SQLite Double-Quoted Strings (#2057)
Browse files Browse the repository at this point in the history
* Fix __init__.py

* Fix activity_pinger.py

* Fix activity_processor.py

* Fix database.py

* Fix datafactory.py

* Fix exporter.py

* Fix graphs.py

* Fix libraries.py

* Fix mobile_app.py

* Fix newsletter_handler.py

* Fix newsletters.py

* Fix notification_handler.py

* Fix notifiers.py

* Fix plexivity_import.py

* Fix plexwatch_import.py

* Fix users.py

* Fix webauth.py
  • Loading branch information
JonnyWong16 committed May 15, 2023
1 parent 3a1d632 commit f39b9f9
Show file tree
Hide file tree
Showing 17 changed files with 2,221 additions and 2,218 deletions.
1,519 changes: 761 additions & 758 deletions plexpy/__init__.py

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions plexpy/activity_pinger.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,22 @@ def check_active_sessions(ws_request=False):
# Using the set config parameter as the interval, probably not the most accurate but
# it will have to do for now. If it's a websocket request don't use this method.
paused_counter = int(stream['paused_counter']) + plexpy.CONFIG.MONITORING_INTERVAL
monitor_db.action('UPDATE sessions SET paused_counter = ? '
'WHERE session_key = ? AND rating_key = ?',
monitor_db.action("UPDATE sessions SET paused_counter = ? "
"WHERE session_key = ? AND rating_key = ?",
[paused_counter, stream['session_key'], stream['rating_key']])

if session['state'] == 'buffering' and plexpy.CONFIG.BUFFER_THRESHOLD > 0:
# The stream is buffering so we need to increment the buffer_count
# We're going just increment on every monitor ping,
# would be difficult to keep track otherwise
monitor_db.action('UPDATE sessions SET buffer_count = buffer_count + 1 '
'WHERE session_key = ? AND rating_key = ?',
monitor_db.action("UPDATE sessions SET buffer_count = buffer_count + 1 "
"WHERE session_key = ? AND rating_key = ?",
[stream['session_key'], stream['rating_key']])

# Check the current buffer count and last buffer to determine if we should notify
buffer_values = monitor_db.select('SELECT buffer_count, buffer_last_triggered '
'FROM sessions '
'WHERE session_key = ? AND rating_key = ?',
buffer_values = monitor_db.select("SELECT buffer_count, buffer_last_triggered "
"FROM sessions "
"WHERE session_key = ? AND rating_key = ?",
[stream['session_key'], stream['rating_key']])

if buffer_values[0]['buffer_count'] >= plexpy.CONFIG.BUFFER_THRESHOLD:
Expand All @@ -125,9 +125,9 @@ def check_active_sessions(ws_request=False):
logger.info("Tautulli Monitor :: User '%s' has triggered a buffer warning."
% stream['user'])
# Set the buffer trigger time
monitor_db.action('UPDATE sessions '
'SET buffer_last_triggered = strftime("%s","now") '
'WHERE session_key = ? AND rating_key = ?',
monitor_db.action("UPDATE sessions "
"SET buffer_last_triggered = strftime('%s', 'now') "
"WHERE session_key = ? AND rating_key = ?",
[stream['session_key'], stream['rating_key']])

plexpy.NOTIFY_QUEUE.put({'stream_data': stream.copy(), 'notify_action': 'on_buffer'})
Expand All @@ -139,9 +139,9 @@ def check_active_sessions(ws_request=False):
logger.info("Tautulli Monitor :: User '%s' has triggered multiple buffer warnings."
% stream['user'])
# Set the buffer trigger time
monitor_db.action('UPDATE sessions '
'SET buffer_last_triggered = strftime("%s","now") '
'WHERE session_key = ? AND rating_key = ?',
monitor_db.action("UPDATE sessions "
"SET buffer_last_triggered = strftime('%s', 'now') "
"WHERE session_key = ? AND rating_key = ?",
[stream['session_key'], stream['rating_key']])

plexpy.NOTIFY_QUEUE.put({'stream_data': stream.copy(), 'notify_action': 'on_buffer'})
Expand Down Expand Up @@ -171,8 +171,8 @@ def check_active_sessions(ws_request=False):
if not stream['stopped']:
# Set the stream stop time
stream['stopped'] = helpers.timestamp()
monitor_db.action('UPDATE sessions SET stopped = ?, state = ? '
'WHERE session_key = ? AND rating_key = ?',
monitor_db.action("UPDATE sessions SET stopped = ?, state = ? "
"WHERE session_key = ? AND rating_key = ?",
[stream['stopped'], 'stopped', stream['session_key'], stream['rating_key']])

progress_percent = helpers.get_percent(stream['view_offset'], stream['duration'])
Expand Down
78 changes: 39 additions & 39 deletions plexpy/activity_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ def write_session_history(self, session=None, import_metadata=None, is_import=Fa

if session['live']:
# Check if we should group the session, select the last guid from the user
query = 'SELECT session_history.id, session_history_metadata.guid, session_history.reference_id ' \
'FROM session_history ' \
'JOIN session_history_metadata ON session_history.id == session_history_metadata.id ' \
'WHERE session_history.user_id = ? ORDER BY session_history.id DESC LIMIT 1 '
query = "SELECT session_history.id, session_history_metadata.guid, session_history.reference_id " \
"FROM session_history " \
"JOIN session_history_metadata ON session_history.id == session_history_metadata.id " \
"WHERE session_history.user_id = ? ORDER BY session_history.id DESC LIMIT 1 "

args = [session['user_id']]

Expand All @@ -351,8 +351,8 @@ def write_session_history(self, session=None, import_metadata=None, is_import=Fa

else:
# Check if we should group the session, select the last two rows from the user
query = 'SELECT id, rating_key, view_offset, reference_id FROM session_history ' \
'WHERE user_id = ? AND rating_key = ? ORDER BY id DESC LIMIT 2 '
query = "SELECT id, rating_key, view_offset, reference_id FROM session_history " \
"WHERE user_id = ? AND rating_key = ? ORDER BY id DESC LIMIT 2 "

args = [session['user_id'], session['rating_key']]

Expand All @@ -375,7 +375,7 @@ def write_session_history(self, session=None, import_metadata=None, is_import=Fa
marker_first, marker_final
)

query = 'UPDATE session_history SET reference_id = ? WHERE id = ? '
query = "UPDATE session_history SET reference_id = ? WHERE id = ? "

# If previous session view offset less than watched percent,
# and new session view offset is greater,
Expand Down Expand Up @@ -547,21 +547,21 @@ def write_session_history(self, session=None, import_metadata=None, is_import=Fa
return session['id']

def get_sessions(self, user_id=None, ip_address=None):
query = 'SELECT * FROM sessions'
query = "SELECT * FROM sessions"
args = []

if str(user_id).isdigit():
ip = ' GROUP BY ip_address' if ip_address else ''
query += ' WHERE user_id = ?' + ip
ip = " GROUP BY ip_address" if ip_address else ""
query += " WHERE user_id = ?" + ip
args.append(user_id)

sessions = self.db.select(query, args)
return sessions

def get_session_by_key(self, session_key=None):
if str(session_key).isdigit():
session = self.db.select_single('SELECT * FROM sessions '
'WHERE session_key = ? ',
session = self.db.select_single("SELECT * FROM sessions "
"WHERE session_key = ? ",
args=[session_key])
if session:
return session
Expand All @@ -570,8 +570,8 @@ def get_session_by_key(self, session_key=None):

def get_session_by_id(self, session_id=None):
if session_id:
session = self.db.select_single('SELECT * FROM sessions '
'WHERE session_id = ? ',
session = self.db.select_single("SELECT * FROM sessions "
"WHERE session_id = ? ",
args=[session_id])
if session:
return session
Expand All @@ -597,15 +597,15 @@ def set_session_state(self, session_key=None, state=None, **kwargs):

def delete_session(self, session_key=None, row_id=None):
if str(session_key).isdigit():
self.db.action('DELETE FROM sessions WHERE session_key = ?', [session_key])
self.db.action("DELETE FROM sessions WHERE session_key = ?", [session_key])
elif str(row_id).isdigit():
self.db.action('DELETE FROM sessions WHERE id = ?', [row_id])
self.db.action("DELETE FROM sessions WHERE id = ?", [row_id])

def set_session_last_paused(self, session_key=None, timestamp=None):
if str(session_key).isdigit():
result = self.db.select('SELECT last_paused, paused_counter '
'FROM sessions '
'WHERE session_key = ?', args=[session_key])
result = self.db.select("SELECT last_paused, paused_counter "
"FROM sessions "
"WHERE session_key = ?", args=[session_key])

paused_counter = None
for session in result:
Expand All @@ -626,15 +626,15 @@ def set_session_last_paused(self, session_key=None, timestamp=None):

def increment_session_buffer_count(self, session_key=None):
if str(session_key).isdigit():
self.db.action('UPDATE sessions SET buffer_count = buffer_count + 1 '
'WHERE session_key = ?',
self.db.action("UPDATE sessions SET buffer_count = buffer_count + 1 "
"WHERE session_key = ?",
[session_key])

def get_session_buffer_count(self, session_key=None):
if str(session_key).isdigit():
buffer_count = self.db.select_single('SELECT buffer_count '
'FROM sessions '
'WHERE session_key = ?',
buffer_count = self.db.select_single("SELECT buffer_count "
"FROM sessions "
"WHERE session_key = ?",
[session_key])
if buffer_count:
return buffer_count['buffer_count']
Expand All @@ -643,15 +643,15 @@ def get_session_buffer_count(self, session_key=None):

def set_session_buffer_trigger_time(self, session_key=None):
if str(session_key).isdigit():
self.db.action('UPDATE sessions SET buffer_last_triggered = strftime("%s","now") '
'WHERE session_key = ?',
self.db.action("UPDATE sessions SET buffer_last_triggered = strftime('%s', 'now') "
"WHERE session_key = ?",
[session_key])

def get_session_buffer_trigger_time(self, session_key=None):
if str(session_key).isdigit():
last_time = self.db.select_single('SELECT buffer_last_triggered '
'FROM sessions '
'WHERE session_key = ?',
last_time = self.db.select_single("SELECT buffer_last_triggered "
"FROM sessions "
"WHERE session_key = ?",
[session_key])
if last_time:
return last_time['buffer_last_triggered']
Expand All @@ -660,12 +660,12 @@ def get_session_buffer_trigger_time(self, session_key=None):

def set_temp_stopped(self):
stopped_time = helpers.timestamp()
self.db.action('UPDATE sessions SET stopped = ?', [stopped_time])
self.db.action("UPDATE sessions SET stopped = ?", [stopped_time])

def increment_write_attempts(self, session_key=None):
if str(session_key).isdigit():
session = self.get_session_by_key(session_key=session_key)
self.db.action('UPDATE sessions SET write_attempts = ? WHERE session_key = ?',
self.db.action("UPDATE sessions SET write_attempts = ? WHERE session_key = ?",
[session['write_attempts'] + 1, session_key])

def set_marker(self, session_key=None, marker_idx=None, marker_type=None):
Expand All @@ -674,13 +674,13 @@ def set_marker(self, session_key=None, marker_idx=None, marker_type=None):
int(marker_type == 'commercial'),
int(marker_type == 'credits')
]
self.db.action('UPDATE sessions SET intro = ?, commercial = ?, credits = ?, marker = ? '
'WHERE session_key = ?',
self.db.action("UPDATE sessions SET intro = ?, commercial = ?, credits = ?, marker = ? "
"WHERE session_key = ?",
marker_args + [marker_idx, session_key])

def set_watched(self, session_key=None):
self.db.action('UPDATE sessions SET watched = ? '
'WHERE session_key = ?',
self.db.action("UPDATE sessions SET watched = ? "
"WHERE session_key = ?",
[1, session_key])

def write_continued_session(self, user_id=None, machine_id=None, media_type=None, stopped=None):
Expand All @@ -689,9 +689,9 @@ def write_continued_session(self, user_id=None, machine_id=None, media_type=None
self.db.upsert(table_name='sessions_continued', key_dict=keys, value_dict=values)

def is_initial_stream(self, user_id=None, machine_id=None, media_type=None, started=None):
last_session = self.db.select_single('SELECT stopped '
'FROM sessions_continued '
'WHERE user_id = ? AND machine_id = ? AND media_type = ? '
'ORDER BY stopped DESC',
last_session = self.db.select_single("SELECT stopped "
"FROM sessions_continued "
"WHERE user_id = ? AND machine_id = ? AND media_type = ? "
"ORDER BY stopped DESC",
[user_id, machine_id, media_type])
return int(started - last_session.get('stopped', 0) >= plexpy.CONFIG.NOTIFY_CONTINUED_SESSION_THRESHOLD)

0 comments on commit f39b9f9

Please sign in to comment.