#125 add in checks for when Tautulli friendly name has been edited.
if edited then fallback to use userID to match Tautulli to Plex. Check if user exists in Tautulli but not Plex
This commit is contained in:
parent
542f58b510
commit
2a39697acd
@ -51,6 +51,9 @@ if sess.verify is False:
|
|||||||
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
||||||
|
|
||||||
sections_lst = [x.title for x in plex.library.sections()]
|
sections_lst = [x.title for x in plex.library.sections()]
|
||||||
|
admin = {plex.myPlexAccount().id: plex.myPlexAccount().title}
|
||||||
|
users_dict = {x.id: x.title for x in plex.myPlexAccount().users()}
|
||||||
|
users_dict.update(admin)
|
||||||
today = time.mktime(datetime.datetime.today().timetuple())
|
today = time.mktime(datetime.datetime.today().timetuple())
|
||||||
|
|
||||||
|
|
||||||
@ -72,6 +75,22 @@ def get_users_table():
|
|||||||
print("Tautulli API 'get_users_table' request failed: {0}.".format(e))
|
print("Tautulli API 'get_users_table' request failed: {0}.".format(e))
|
||||||
|
|
||||||
|
|
||||||
|
def last_entry(last_seen, username):
|
||||||
|
# Display user's last history entry
|
||||||
|
if last_seen > 1:
|
||||||
|
print('{} was last seen {} days ago.'.format(username, last_seen))
|
||||||
|
elif int(last_seen) == 1:
|
||||||
|
print('{} was last seen yesterday.'.format(username))
|
||||||
|
else:
|
||||||
|
hours_ago = last_seen * 24
|
||||||
|
if int(hours_ago) != 0:
|
||||||
|
hours_ago = int(hours_ago)
|
||||||
|
print('{} was last seen {} hours ago.'.format(username, hours_ago))
|
||||||
|
else:
|
||||||
|
minutes_ago = int(hours_ago * 60)
|
||||||
|
print('{} was last seen {} minutes ago.'.format(username, minutes_ago))
|
||||||
|
|
||||||
|
|
||||||
def unshare(user):
|
def unshare(user):
|
||||||
print('{user} has reached inactivity limit. Unsharing.'.format(user=user))
|
print('{user} has reached inactivity limit. Unsharing.'.format(user=user))
|
||||||
plex.myPlexAccount().updateFriend(user=user, server=plex, removeSections=True, sections=sections_lst)
|
plex.myPlexAccount().updateFriend(user=user, server=plex, removeSections=True, sections=sections_lst)
|
||||||
@ -94,25 +113,26 @@ def main():
|
|||||||
last_seen = int(last_seen)
|
last_seen = int(last_seen)
|
||||||
|
|
||||||
username = user['friendly_name']
|
username = user['friendly_name']
|
||||||
if username not in USER_IGNORE:
|
user_id = user['user_id']
|
||||||
if last_seen > REMOVE_LIMIT:
|
|
||||||
print('{} was last seen {} days ago. Removing.'.format(username, last_seen))
|
# Check if friendly username from Tautulli does not exist in Plex
|
||||||
remove_friend(username)
|
if username not in users_dict.values():
|
||||||
elif last_seen > UNSHARE_LIMIT:
|
try:
|
||||||
print('{} was last seen {} days ago. Unshsring.'.format(username, last_seen))
|
username = users_dict[user_id]
|
||||||
unshare(username)
|
except KeyError:
|
||||||
elif last_seen > 1:
|
print('User: {} has records in Tautulli but does not exist in Plex.'.format(username))
|
||||||
print('{} was last seen {} days ago.'.format(username, last_seen))
|
last_entry(last_seen, username)
|
||||||
elif int(last_seen) == 1:
|
else:
|
||||||
print('{} was last seen yesterday.'.format(username))
|
# Only users that still exist in Plex will continue
|
||||||
else:
|
if username not in USER_IGNORE:
|
||||||
hours_ago = last_seen * 24
|
if last_seen > REMOVE_LIMIT:
|
||||||
if int(hours_ago) != 0:
|
print('{} was last seen {} days ago. Removing.'.format(username, last_seen))
|
||||||
hours_ago = int(hours_ago)
|
remove_friend(username)
|
||||||
print('{} was last seen {} hours ago.'.format(username, hours_ago))
|
elif last_seen > UNSHARE_LIMIT:
|
||||||
|
print('{} was last seen {} days ago. Unshsring.'.format(username, last_seen))
|
||||||
|
unshare(username)
|
||||||
else:
|
else:
|
||||||
minutes_ago = int(hours_ago * 60)
|
last_entry(last_seen, username)
|
||||||
print('{} was last seen {} minutes ago.'.format(username, minutes_ago))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user