Skip to content

Instantly share code, notes, and snippets.

@blacktwin
Created January 19, 2017 20:04
Show Gist options
  • Save blacktwin/093803e820bc914fe1086accf5df580d to your computer and use it in GitHub Desktop.
Save blacktwin/093803e820bc914fe1086accf5df580d to your computer and use it in GitHub Desktop.
Use with stream_limiter_ban_email.py to clear watch history of banned users.
"""
Use with stream_limiter_ban_email.py to clear watch history of banned users.
api_sql must be manually enabled in the config file.
"""
import requests
import sys
## EDIT THESE SETTINGS ###
PLEXPY_APIKEY = 'XXXXXX' # Your PlexPy API key
PLEXPY_URL = 'http://localhost:8181/' # Your PlexPy URL
user_id = 123456
rating_key = 12345
## DO NOT EDIT BELOW ##
def sql_clear(query):
try:
payload = {'apikey': PLEXPY_APIKEY,
'cmd': 'sql',
'query': query}
requests.post(PLEXPY_URL.rstrip('/') + '/api/v2', params=payload)
except Exception as e:
sys.stderr.write("PlexPy API 'get_sql' request failed: {0}.".format(e))
if __name__ == "__main__":
sess_his = "DELETE FROM session_history WHERE user_id = %s AND rating_key = %s;" % (user_id, rating_key)
sess_med = "DELETE FROM session_history_media_info WHERE id NOT IN (SELECT id FROM session_history);"
sess_met = "DELETE FROM session_history_metadata WHERE id NOT IN (SELECT id FROM session_history);"
sql_clear(sess_his)
sql_clear(sess_med)
sql_clear(sess_met)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment