diff --git a/reporting/check_play.py b/reporting/check_play.py index 75d4ce5..ed841b2 100644 --- a/reporting/check_play.py +++ b/reporting/check_play.py @@ -33,6 +33,7 @@ class UserHIS(object): data = data or {} self.watched = [d['watched_status'] for d in data] + def get_history(): # Get the user IP list from Tautulli payload = {'apikey': TAUTULLI_APIKEY, diff --git a/scriptHeaderTemplate.txt b/scriptHeaderTemplate.txt index 8c2bdf9..924beac 100644 --- a/scriptHeaderTemplate.txt +++ b/scriptHeaderTemplate.txt @@ -1,4 +1,8 @@ """ +Description: {description} +Author: {author} +Requires: {requirements} + Enabling Scripts in Tautulli: Taultulli > Settings > Notification Agents > Add a Notification Agent > Script @@ -7,7 +11,7 @@ Taultulli > Settings > Notification Agents > New Script > Configuration: Script Name: {script_name} Set Script Timeout: {timeout} - Description: {description} + Description: {Tautulli_description} Save Triggers: diff --git a/utility/purge_removed_plex_friends.py b/utility/purge_removed_plex_friends.py new file mode 100644 index 0000000..bca2b6a --- /dev/null +++ b/utility/purge_removed_plex_friends.py @@ -0,0 +1,40 @@ +""" +Description: Purge Tautulli users that no longer exist as a friend in Plex +Author: DirtyCajunRice +Requires: requests, plexapi +""" + +import requests +from plexapi.myplex import MyPlexAccount + +TAUTULLI_BASE_URL = '' +TAUTULLI_API_KEY = '' + +PLEX_USERNAME = '' +PLEX_PASSWORD = '' + +# Do you want to back up the database before deleting? +BACKUP_DB = True + +# Do not edit past this line # +account = MyPlexAccount(PLEX_USERNAME, PLEX_PASSWORD) + +payload = {'apikey': TAUTULLI_API_KEY, 'cmd': 'get_user_names'} +tautulli_users = requests.get('http://{}/api/v2' + .format(TAUTULLI_BASE_URL), params=payload).json()['response']['data'] + +plex_friend_ids = [friend.id for friend in account.users()] +tautulli_user_ids = [user['user_id'] for user in tautulli_users] + +removed_user_ids = [user_id for user_id in tautulli_user_ids if user_id not in plex_friend_ids] + +if BACKUP_DB: + payload['cmd'] = 'backup_db' + backup = requests.get('http://{}/api/v2'.format(TAUTULLI_BASE_URL), params=payload) + +if removed_user_ids: + payload['cmd'] = 'delete_user' + + for user_id in removed_user_ids: + payload['user_id'] = user_id + remove_user = requests.get('http://{}/api/v2'.format(TAUTULLI_BASE_URL), params=payload) \ No newline at end of file