# Buggy code
def get_last_updated_series(self, from_time, weeks=1, filter_show_list=None):
    """Retrieve a list with updated shows.

    :param from_time: epoch timestamp, with the start date/time
    :param weeks: number of weeks to get updates for.
    :param filter_show_list: Optional list of show objects, to use for filtering the returned list.
    :returns: A list of show_id's.
    """
    total_updates = []
    updates = True

    count = 0
    try:
        while updates and count < weeks:
            updates = (
                self.config["session"].updates_api.updated_query_get(from_time).data
            )
            if updates is not None:
                last_update_ts = max(x.last_updated for x in updates)
                from_time = last_update_ts
                total_updates += [int(_.id) for _ in updates]
            count += 1
    except ApiException as e:
        if e.status == 401:
            raise IndexerAuthFailed(
                "Authentication failed, possible bad api key. reason: {reason} ({status})".format(
                    reason=e.reason, status=e.status
                )
            )
        raise IndexerUnavailable(
            "Error connecting to Tvdb api. Caused by: {0}".format(e.reason)
        )
    except RequestException as e:
        raise IndexerUnavailable(
            "Error connecting to Tvdb api. Caused by: {0}".format(e.reason)
        )

    if total_updates and filter_show_list:
        new_list = []
        for show in filter_show_list:
            if show.indexerid in total_updates:
                new_list.append(show.indexerid)
        total_updates = new_list

    return total_updates


# Traceback (ValueError)
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529546405 [Status: 200]
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:18 ERROR    SHOWUPDATER :: [c65ca26] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show SIX. Cause: max() arg is an empty sequence.
Traceback (most recent call last):
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/show_updater.py", line 91, in run
    last_update, update_max_weeks
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/fallback.py", line 136, in __call__
    return self.func(*args, **kwargs)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/tvdbv2_api.py", line 633, in get_last_updated_series
    last_update_ts = max(x.last_updated for x in updates)
ValueError: max() arg is an empty sequence
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] Keeping Plex fallback enabled as fallback timeout not reached
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529460039 [Status: 200]
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529546405 [Status: 200]
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:18 WARNING  SHOWUPDATER :: [c65ca26] could not connect to TheTvdb.com, with reason 'max() arg is an empty sequence'
2018-06-21 04:00:18 WARNING  SHOWUPDATER :: [c65ca26] Enabling Plex fallback as TheTvdb.com API is having some connectivity issues
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529460039 [Status: 200]
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529546405 [Status: 200]
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:18 ERROR    SHOWUPDATER :: [c65ca26] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show Taboo (2017). Cause: max() arg is an empty sequence.
Traceback (most recent call last):
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/show_updater.py", line 91, in run
    last_update, update_max_weeks
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/fallback.py", line 136, in __call__
    return self.func(*args, **kwargs)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/tvdbv2_api.py", line 633, in get_last_updated_series
    last_update_ts = max(x.last_updated for x in updates)
ValueError: max() arg is an empty sequence
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] Keeping Plex fallback enabled as fallback timeout not reached
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529460039 [Status: 200]
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529546405 [Status: 200]
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:18 WARNING  SHOWUPDATER :: [c65ca26] could not connect to TheTvdb.com, with reason 'max() arg is an empty sequence'
2018-06-21 04:00:18 WARNING  SHOWUPDATER :: [c65ca26] Enabling Plex fallback as TheTvdb.com API is having some connectivity issues
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529460039 [Status: 200]
2018-06-21 04:00:18 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529546405 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 ERROR    SHOWUPDATER :: [c65ca26] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show Billions. Cause: max() arg is an empty sequence.
Traceback (most recent call last):
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/show_updater.py", line 91, in run
    last_update, update_max_weeks
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/fallback.py", line 136, in __call__
    return self.func(*args, **kwargs)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/tvdbv2_api.py", line 633, in get_last_updated_series
    last_update_ts = max(x.last_updated for x in updates)
ValueError: max() arg is an empty sequence
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] Keeping Plex fallback enabled as fallback timeout not reached
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529460039 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529546405 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 WARNING  SHOWUPDATER :: [c65ca26] could not connect to TheTvdb.com, with reason 'max() arg is an empty sequence'
2018-06-21 04:00:19 WARNING  SHOWUPDATER :: [c65ca26] Enabling Plex fallback as TheTvdb.com API is having some connectivity issues
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529460039 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529546405 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 ERROR    SHOWUPDATER :: [c65ca26] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show American Gods. Cause: max() arg is an empty sequence.
Traceback (most recent call last):
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/show_updater.py", line 91, in run
    last_update, update_max_weeks
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/fallback.py", line 136, in __call__
    return self.func(*args, **kwargs)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/tvdbv2_api.py", line 633, in get_last_updated_series
    last_update_ts = max(x.last_updated for x in updates)
ValueError: max() arg is an empty sequence
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] Keeping Plex fallback enabled as fallback timeout not reached
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529460039 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529546405 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 WARNING  SHOWUPDATER :: [c65ca26] could not connect to TheTvdb.com, with reason 'max() arg is an empty sequence'
2018-06-21 04:00:19 WARNING  SHOWUPDATER :: [c65ca26] Enabling Plex fallback as TheTvdb.com API is having some connectivity issues
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529460039 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529546405 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 ERROR    SHOWUPDATER :: [c65ca26] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show Salvation. Cause: max() arg is an empty sequence.
Traceback (most recent call last):
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/show_updater.py", line 91, in run
    last_update, update_max_weeks
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/fallback.py", line 136, in __call__
    return self.func(*args, **kwargs)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/tvdbv2_api.py", line 633, in get_last_updated_series
    last_update_ts = max(x.last_updated for x in updates)
ValueError: max() arg is an empty sequence
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] Keeping Plex fallback enabled as fallback timeout not reached
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529460039 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529546405 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 WARNING  SHOWUPDATER :: [c65ca26] could not connect to TheTvdb.com, with reason 'max() arg is an empty sequence'
2018-06-21 04:00:19 WARNING  SHOWUPDATER :: [c65ca26] Enabling Plex fallback as TheTvdb.com API is having some connectivity issues
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529460039 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529546405 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 ERROR    SHOWUPDATER :: [c65ca26] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show Star Trek: Discovery. Cause: max() arg is an empty sequence.
Traceback (most recent call last):
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/show_updater.py", line 91, in run
    last_update, update_max_weeks
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/fallback.py", line 136, in __call__
    return self.func(*args, **kwargs)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/tvdbv2_api.py", line 633, in get_last_updated_series
    last_update_ts = max(x.last_updated for x in updates)
ValueError: max() arg is an empty sequence
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] Keeping Plex fallback enabled as fallback timeout not reached
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529460039 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529546405 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 WARNING  SHOWUPDATER :: [c65ca26] could not connect to TheTvdb.com, with reason 'max() arg is an empty sequence'
2018-06-21 04:00:19 WARNING  SHOWUPDATER :: [c65ca26] Enabling Plex fallback as TheTvdb.com API is having some connectivity issues
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529460039 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] GET URL: https://tvdb2.plex.tv/updated/query?fromTime=1529546405 [Status: 200]
2018-06-21 04:00:19 DEBUG    SHOWUPDATER :: [c65ca26] User-Agent: Medusa/0.2.5 (Linux; 3.10.102; 06e09954-73d2-11e8-85ef-02425b5a509e)
2018-06-21 04:00:19 ERROR    SHOWUPDATER :: [c65ca26] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show The Exorcist. Cause: max() arg is an empty sequence.
Traceback (most recent call last):
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/show_updater.py", line 91, in run
    last_update, update_max_weeks
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/fallback.py", line 136, in __call__
    return self.func(*args, **kwargs)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/medusa/indexers/tvdbv2/tvdbv2_api.py", line 633, in get_last_updated_series
    last_update_ts = max(x.last_updated for x in updates)
ValueError: max() arg is an empty sequence

# Fixed code
def get_last_updated_series(self, from_time, weeks=1, filter_show_list=None):
    """Retrieve a list with updated shows.

    :param from_time: epoch timestamp, with the start date/time
    :param weeks: number of weeks to get updates for.
    :param filter_show_list: Optional list of show objects, to use for filtering the returned list.
    :returns: A list of show_id's.
    """
    total_updates = []
    updates = True

    count = 0
    try:
        while updates and count < weeks:
            updates = (
                self.config["session"].updates_api.updated_query_get(from_time).data
            )
            if updates:
                last_update_ts = max(x.last_updated for x in updates)
                from_time = last_update_ts
                total_updates += [int(_.id) for _ in updates]
            count += 1
    except ApiException as e:
        if e.status == 401:
            raise IndexerAuthFailed(
                "Authentication failed, possible bad api key. reason: {reason} ({status})".format(
                    reason=e.reason, status=e.status
                )
            )
        raise IndexerUnavailable(
            "Error connecting to Tvdb api. Caused by: {0}".format(e.reason)
        )
    except RequestException as e:
        raise IndexerUnavailable(
            "Error connecting to Tvdb api. Caused by: {0}".format(e.reason)
        )

    if total_updates and filter_show_list:
        new_list = []
        for show in filter_show_list:
            if show.indexerid in total_updates:
                new_list.append(show.indexerid)
        total_updates = new_list

    return total_updates