update limit section for new history collector

This commit is contained in:
blacktwin 2019-10-14 17:25:58 -04:00
parent 82c7704fab
commit b5fd014c17

View File

@ -359,21 +359,30 @@ if __name__ == "__main__":
# todo-me need more flexibility for pulling history # todo-me need more flexibility for pulling history
# limit work requires gp_rating_key only? Needs more options. # limit work requires gp_rating_key only? Needs more options.
if opts.jbop == 'limit' and opts.grandparent_rating_key: if opts.jbop == 'limit' and opts.grandparent_rating_key:
history = get_history(username=opts.username, start_date=True) ep_watched = []
stopped_time = []
for dates in dates:
history_lst.append(get_history(username=opts.username, start_date=date))
# If message is not already defined use default message # If message is not already defined use default message
if not message: if not message:
message = LIMIT_MESSAGE.format(delay=opts.delay) message = LIMIT_MESSAGE.format(delay=opts.delay)
ep_watched = [data['watched_status'] for data in history['data'] for history in history_lst:
if data['grandparent_rating_key'] == opts.grandparent_rating_key and ep_watched += [data['watched_status'] for data in history['data']
data['watched_status'] == 1] if data['grandparent_rating_key'] == opts.grandparent_rating_key and
data['watched_status'] == 1]
stopped_time += [data['stopped'] for data in history['data']
if data['grandparent_rating_key'] == opts.grandparent_rating_key and
data['watched_status'] == 1]
# If show has no history for date range start at 0.
if not ep_watched: if not ep_watched:
ep_watched = 0 ep_watched = 0
else: else:
ep_watched = sum(ep_watched) ep_watched = sum(ep_watched)
stopped_time = [data['stopped'] for data in history['data'] # If show episode have not been stopped (completed?) then use current time.
if data['grandparent_rating_key'] == opts.grandparent_rating_key and # Last stopped time is needed to test against auto play timer
data['watched_status'] == 1]
if not stopped_time: if not stopped_time:
stopped_time = unix_time stopped_time = unix_time
else: else:
@ -384,9 +393,9 @@ if __name__ == "__main__":
sys.exit(1) sys.exit(1)
if ep_watched >= total_limit: if ep_watched >= total_limit:
print("{}'s limit is {} and has watched {} episodes of this show today.".format( print("{}'s limit is {} and has watched {} episodes of this show.".format(
opts.username, total_limit, ep_watched)) opts.username, total_limit, ep_watched))
terminate_session(opts.sessionId, message, opts.notify, opts.username) terminate_session(opts.sessionId, message, opts.notify, opts.username)
else: else:
print("{}'s limit is {} but has only watched {} episodes of this show today.".format( print("{}'s limit is {} but has only watched {} episodes of this show.".format(
opts.username, total_limit, ep_watched)) opts.username, total_limit, ep_watched))