From fc639507c8c6082703e8a4d5d9e1920d3c4c99e5 Mon Sep 17 00:00:00 2001 From: "Nicholas St. Germain" Date: Wed, 14 Mar 2018 12:44:50 -0500 Subject: [PATCH 1/2] Create purge_removed_plex_friends.py --- utility/purge_removed_plex_friends.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 utility/purge_removed_plex_friends.py diff --git a/utility/purge_removed_plex_friends.py b/utility/purge_removed_plex_friends.py new file mode 100644 index 0000000..4390b9a --- /dev/null +++ b/utility/purge_removed_plex_friends.py @@ -0,0 +1,27 @@ +import requests +from plexapi.myplex import MyPlexAccount + +TAUTULLI_BASE_URL = '192.168.1.100:8181' +TAUTULLI_API_KEY = 'asd8a9sd8789asd87f9aasdf' + +PLEX_USERNAME = 'someuser' +PLEX_PASSWORD = 'somepassword' + +# 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 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) From 735da3311d3573c2be66de68f610d4f1a1feda25 Mon Sep 17 00:00:00 2001 From: "Nicholas St. Germain" Date: Wed, 14 Mar 2018 13:07:56 -0500 Subject: [PATCH 2/2] added backup of db --- utility/purge_removed_plex_friends.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utility/purge_removed_plex_friends.py b/utility/purge_removed_plex_friends.py index 4390b9a..cfc4886 100644 --- a/utility/purge_removed_plex_friends.py +++ b/utility/purge_removed_plex_friends.py @@ -7,6 +7,9 @@ TAUTULLI_API_KEY = 'asd8a9sd8789asd87f9aasdf' PLEX_USERNAME = 'someuser' PLEX_PASSWORD = 'somepassword' +# 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) @@ -19,6 +22,10 @@ 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'