Skip to content

Instantly share code, notes, and snippets.

@JonnyWong16
Last active June 11, 2023 14:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonnyWong16/cb1b53e71b89d2159313 to your computer and use it in GitHub Desktop.
Save JonnyWong16/cb1b53e71b89d2159313 to your computer and use it in GitHub Desktop.
Delete Tautulli history older than "X" days
### WARNING: This script has not been tested! ###
# 1. Set api_sql = 1 in the config.ini file.
# 2. Install the requests module for python.
# pip install requests
# 3. Use some method to run the script on a schedule.
import requests
## EDIT THESE SETTINGS ##
TAUTULLI_URL = 'http://localhost:8181/' # Your Tautulli URL
TAUTULLI_APIKEY = '#####' # Your Tautulli API Key
HISTORY_DAYS_TO_KEEP = 7
## CODE BELOW ##
queries = [
'DELETE FROM session_history WHERE datetime(started, "unixepoch", "localtime") < datetime("now", "-{0} days", "localtime");'.format(HISTORY_DAYS_TO_KEEP),
'DELETE FROM session_history_media_info WHERE id NOT IN (SELECT id FROM session_history);',
'DELETE FROM session_history_metadata WHERE id NOT IN (SELECT id FROM session_history);'
]
url = TAUTULLI_URL.rstrip('/') + '/api/v2'
params = {'apikey': TAUTULLI_APIKEY,
'cmd': 'sql'}
for query in queries:
params['query'] = query
requests.post(url, params=params)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment