Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions plextraktsync/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ def wrap(*args, **kwargs):
name = fn.__name__
module = importlib.import_module(f".commands.{name}", package=__package__)
cmd = getattr(module, name)

try:
cmd(*args, **kwargs)
except RuntimeError as e:
from click import ClickException

raise ClickException(f"Error running {name} command: {str(e)}")
cmd(*args, **kwargs)

return wrap

Expand Down
21 changes: 21 additions & 0 deletions plextraktsync/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Factory:
def trakt_api(self):
from plextraktsync.trakt_api import TraktApi

self.monkey_patch_trakt()

config = self.run_config()
trakt = TraktApi(batch_delay=config.batch_delay)

Expand Down Expand Up @@ -159,6 +161,25 @@ def config(self):

return Config()

@staticmethod
def monkey_patch_trakt():
from collections import namedtuple

import trakt.users

# Add `type` to UserList named tuple:
# - https://github.com/moogar0880/PyTrakt/pull/206
# Monkey patch the class:
# - https://stackoverflow.com/a/28500620/2314626
# - https://stackoverflow.com/a/62160225/2314626
UserListOriginal = trakt.users.UserList
UserListTuple = namedtuple('UserList', UserListOriginal._fields + ('type',))

class UserList(UserListTuple, UserListOriginal):
pass

trakt.users.UserList = UserList


factory = Factory()
logger = factory.logger
Expand Down