add pie chart creation
This commit is contained in:
parent
94128a92cb
commit
1952413639
@ -150,6 +150,31 @@ class Plex:
|
|||||||
return section_totals
|
return section_totals
|
||||||
|
|
||||||
|
|
||||||
|
def make_pie(user_dict, sections_dict):
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
x = len(user_dict.keys())
|
||||||
|
y = len(sections_dict.keys())
|
||||||
|
user_count = 0
|
||||||
|
|
||||||
|
for user, values in user_dict.items():
|
||||||
|
position = 0
|
||||||
|
for library, watched_value in values.items():
|
||||||
|
fracs = [watched_value, sections_dict.get(library)]
|
||||||
|
ax = plt.subplot2grid((x, y), (user_count, position))
|
||||||
|
ax.xaxis.set_major_formatter(plt.NullFormatter())
|
||||||
|
ax.pie(fracs, autopct='%1.1f%%', shadow=True)
|
||||||
|
if user_count == 0:
|
||||||
|
ax.title.set_text(library)
|
||||||
|
if position == 0:
|
||||||
|
ax.set_ylabel(user).set_rotation(0)
|
||||||
|
position += 1
|
||||||
|
user_count += 1
|
||||||
|
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
admin_account = Plex(PLEX_TOKEN)
|
admin_account = Plex(PLEX_TOKEN)
|
||||||
plex_server = Plex(PLEX_TOKEN, PLEX_URL)
|
plex_server = Plex(PLEX_TOKEN, PLEX_URL)
|
||||||
@ -161,25 +186,45 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument('--users', nargs='*', metavar='users', choices=admin_account.all_users().keys(),
|
parser.add_argument('--users', nargs='*', metavar='users', choices=admin_account.all_users().keys(),
|
||||||
help='Users to scan for watched content.\n'
|
help='Users to scan for watched content.\n'
|
||||||
'Choices: %(choices)s')
|
'Choices: %(choices)s')
|
||||||
|
parser.add_argument('--pie', default=False, action='store_true',
|
||||||
|
help='Display pie chart')
|
||||||
|
|
||||||
opts = parser.parse_args()
|
opts = parser.parse_args()
|
||||||
|
|
||||||
|
sections_totals_dict = {}
|
||||||
|
user_dict = {}
|
||||||
|
|
||||||
for library in opts.libraries:
|
for library in opts.libraries:
|
||||||
section_total = plex_server.all_sections_totals(library)
|
section_total = plex_server.all_sections_totals(library)
|
||||||
|
sections_totals_dict[library] = section_total
|
||||||
print("Section: {}, has {} items.".format(library, section_total))
|
print("Section: {}, has {} items.".format(library, section_total))
|
||||||
for user in opts.users:
|
for user in opts.users:
|
||||||
user_account = admin_account.account.user(user)
|
try:
|
||||||
token = user_account.get_token(plex_server.server.machineIdentifier)
|
user_account = admin_account.account.user(user)
|
||||||
user_server = Plex(url=PLEX_URL, token=token)
|
token = user_account.get_token(plex_server.server.machineIdentifier)
|
||||||
section = user_server.server.library.section(library)
|
user_server = Plex(url=PLEX_URL, token=token)
|
||||||
section_watched_lst = []
|
section = user_server.server.library.section(library)
|
||||||
if section.type == 'movie':
|
section_watched_lst = []
|
||||||
section_watched_lst += section.search(unwatched=False)
|
if section.type == 'movie':
|
||||||
elif section.type == 'show':
|
section_watched_lst += section.search(unwatched=False)
|
||||||
section_watched_lst += section.search(libtype='episode', unwatched=False)
|
elif section.type == 'show':
|
||||||
else:
|
section_watched_lst += section.search(libtype='episode', unwatched=False)
|
||||||
continue
|
else:
|
||||||
section_watched_total = len(section_watched_lst)
|
continue
|
||||||
percent_watched = 100 * (float(section_watched_total) / float(section_total))
|
section_watched_total = len(section_watched_lst)
|
||||||
print(" {} has watched {} items ({}%).".format(user, section_watched_total, int(percent_watched)))
|
percent_watched = 100 * (float(section_watched_total) / float(section_total))
|
||||||
|
print(" {} has watched {} items ({}%).".format(user, section_watched_total, int(percent_watched)))
|
||||||
|
|
||||||
|
if user_dict.get(user):
|
||||||
|
user_dict[user].update({library: section_watched_total})
|
||||||
|
else:
|
||||||
|
user_dict[user] = {library: section_watched_total}
|
||||||
|
except Exception as e:
|
||||||
|
print(user, e)
|
||||||
|
if user_dict.get(user):
|
||||||
|
user_dict[user].update({library: 0})
|
||||||
|
else:
|
||||||
|
user_dict[user] = {library: 0}
|
||||||
|
|
||||||
|
if opts.pie:
|
||||||
|
make_pie(user_dict, sections_totals_dict)
|
||||||
|
Loading…
Reference in New Issue
Block a user