From ba5335c1f0ce7b8031a6c3f75b9c07238b34a6d0 Mon Sep 17 00:00:00 2001 From: "Nicholas St. Germain" Date: Thu, 2 May 2019 15:07:46 -0500 Subject: [PATCH 1/2] create ombi_to_tautulli_friendly_name_sync --- .../ombi_to_tautulli_friendly_name_sync.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 utility/ombi_to_tautulli_friendly_name_sync.py diff --git a/utility/ombi_to_tautulli_friendly_name_sync.py b/utility/ombi_to_tautulli_friendly_name_sync.py new file mode 100644 index 0000000..7af5cd5 --- /dev/null +++ b/utility/ombi_to_tautulli_friendly_name_sync.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +""" +Description: Sync Tautulli friendly names with Ombi aliases (Tautulli as master) +Author: DirtyCajunRice +Requires: requests, python3.6+ +""" +from requests import Session +from plexapi.server import CONFIG +from urllib3 import disable_warnings +from urllib3.exceptions import InsecureRequestWarning + +OMBI_BASEURL = '' +OMBI_APIKEY = '' + +TAUTULLI_BASEURL = '' +TAUTULLI_APIKEY = '' + +# Dont Edit Below # +TAUTULLI_BASEURL = TAUTULLI_BASEURL or CONFIG.data['auth'].get('tautulli_baseurl') +TAUTULLI_APIKEY = TAUTULLI_APIKEY or CONFIG.data['auth'].get('tautulli_apikey') +OMBI_BASEURL = OMBI_BASEURL or CONFIG.data['auth'].get('ombi_baseurl') +OMBI_APIKEY = OMBI_APIKEY or CONFIG.data['auth'].get('ombi_apikey') + +disable_warnings(InsecureRequestWarning) +SESSION = Session() +SESSION.verify = False + +HEADERS = {'apiKey': OMBI_APIKEY} +PARAMS = {'apikey': TAUTULLI_APIKEY, 'cmd': 'get_users'} + +TAUTULLI_USERS = SESSION.get('{}/api/v2'.format(TAUTULLI_BASEURL.rstrip('/')), params=PARAMS).json()['response']['data'] +TAUTULLI_MAPPED = {user['username']: user['friendly_name'] for user in TAUTULLI_USERS + if user['user_id'] != 0 and user['friendly_name']} +OMBI_USERS = SESSION.get('{}/api/v1/Identity/Users'.format(OMBI_BASEURL.rstrip('/')), headers=HEADERS).json() + +for user in OMBI_USERS: + if user['userName'] in TAUTULLI_MAPPED and user['alias'] != TAUTULLI_MAPPED[user['userName']]: + print("{}'s alias in Tautulli ({}) is being updated in Ombi from {}".format( + user['userName'], TAUTULLI_MAPPED[user['userName']], user['alias'] or 'empty' + )) + user['alias'] = TAUTULLI_MAPPED[user['userName']] + put = SESSION.put('{}/api/v1/Identity'.format(OMBI_BASEURL.rstrip('/')), json=user, headers=HEADERS) + if put.status_code != 200: + print('Error updating {}'.format(user['userName'])) From ed65e4e9481216905620f2032b54641fe89ffd8d Mon Sep 17 00:00:00 2001 From: "Nicholas St. Germain" Date: Thu, 2 May 2019 15:11:25 -0500 Subject: [PATCH 2/2] rename for arc :P --- ..._name_sync.py => tautulli_friendly_name_to_ombi_alias_sync.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename utility/{ombi_to_tautulli_friendly_name_sync.py => tautulli_friendly_name_to_ombi_alias_sync.py} (100%) diff --git a/utility/ombi_to_tautulli_friendly_name_sync.py b/utility/tautulli_friendly_name_to_ombi_alias_sync.py similarity index 100% rename from utility/ombi_to_tautulli_friendly_name_sync.py rename to utility/tautulli_friendly_name_to_ombi_alias_sync.py