# 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.updates_api.updated_query_get(from_time).data
            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, MaxRetryError, RequestError) as e:
        raise IndexerUnavailable(
            "Error connecting to Tvdb api. Caused by: {0!r}".format(e)
        )

    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 (TypeError)
2017-03-17 02:00:38 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Getting all episodes of [292421]
2017-03-17 02:01:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Indexer info for show The Late Late Show with James Corden: S02E144
2017-03-17 02:01:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Scene numbering enabled show 'The Late Late Show with James Corden', using indexer numbering: S02E144
2017-03-17 02:01:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Converted parsed result James.Corden.2017.03.15.Reese.Witherspoon.720p.WEB.h264-HEAT into title: James Corden, date: 2017-03-15, episode_title: Reese Witherspoon, screen_size: 720p, format: WEB-DL, video_codec: h264, release_group: HEAT, type: episode, parsing_time: 0.200747013092, total_time: None, absolute_episode: [], quality: 720p WEB-DL, episode: [144], season: 2
2017-03-17 02:01:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Matched release 'James.Corden.2017.03.15.Reese.Witherspoon.720p.WEB.h264-HEAT' to a show in your database: 'The Late Late Show with James Corden'
2017-03-17 02:01:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Parsed 'James.Corden.2017.03.15.Reese.Witherspoon.720p.WEB.h264-HEAT' into title: James Corden, date: 2017-03-15, episode_title: Reese Witherspoon, screen_size: 720p, format: WEB-DL, video_codec: h264, release_group: HEAT, type: episode, parsing_time: 0.200747013092, total_time: 57.1374089718, absolute_episode: [], quality: 720p WEB-DL, episode: [144], season: 2
2017-03-17 02:01:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Added RSS item: [James.Corden.2017.03.15.Reese.Witherspoon.720p.WEB.h264-HEAT] to cache: [bithdtv]
2017-03-17 02:01:15 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Time.The.Kalief.Browder.Story.S01E03.720p.WEB.x264-HEAT to a show in your database. Parser result: title: Time The Kalief Browder Story, season: 1, episode: [3], screen_size: 720p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: HEAT, type: episode, parsing_time: 0.193681955338, total_time: 0.560091018677, absolute_episode: [], quality: 720p WEB-DL
2017-03-17 02:01:15 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Seth.Meyers.2017.03.15.Keri.Russell.720p.HDTV.x264-CROOKS to a show in your database. Parser result: title: Seth Meyers, date: 2017-03-15, episode_title: Keri Russell, screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: CROOKS, type: episode, parsing_time: 0.221388101578, total_time: 0.225222110748, absolute_episode: [], quality: 720p HDTV, episode: [], season: None
2017-03-17 02:01:16 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Akibas.Trip.The.Animation.S01E11.720p.WEB.x264-ANiURL to a show in your database. Parser result: title: Akibas Trip The Animation, season: 1, episode: [11], screen_size: 720p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: ANiURL, type: episode, parsing_time: 0.194520950317, total_time: 0.556681871414, absolute_episode: [], quality: 720p WEB-DL
2017-03-17 02:01:16 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Matched release 'The.100.S04E06.We.Will.Rise.1080p.AMZN.WEBRip.DD+5.1.x264-CasStudio.mkv' to a show in your database: 'The 100'
2017-03-17 02:01:16 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Parsed 'The.100.S04E06.We.Will.Rise.1080p.AMZN.WEBRip.DD+5.1.x264-CasStudio.mkv' into title: The 100, season: 4, episode: [6], episode_title: We Will Rise, screen_size: 1080p, streaming_service: Amazon Prime, format: WEBRip, audio_codec: AC3, audio_channels: 5.1, video_codec: h264, video_encoder: x264, release_group: CasStudio, container: mkv, mimetype: video/x-matroska, type: episode, parsing_time: 0.303165912628, total_time: 0.304452180862, absolute_episode: [], quality: 1080p WEB-DL
2017-03-17 02:01:16 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Added RSS item: [The.100.S04E06.We.Will.Rise.1080p.AMZN.WEBRip.DD+5.1.x264-CasStudio.mkv] to cache: [bithdtv]
2017-03-17 02:01:17 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Arrow.S05E16.Checkmate.720p.WEBRip.DD5.1.x264 to a show in your database. Parser result: title: Arrow, season: 5, episode: [16], episode_title: Checkmate, screen_size: 720p, format: WEBRip, audio_codec: AC3, audio_channels: 5.1, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.235898017883, total_time: 0.593179941177, absolute_episode: [], quality: 720p WEB-DL
2017-03-17 02:01:17 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Jimmy.Fallon.2017.03.15.Ice.Cube.720p.HDTV.x264-CROOKS to a show in your database. Parser result: title: Jimmy Fallon, date: 2017-03-15, episode_title: Ice Cube, screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: CROOKS, type: episode, parsing_time: 0.219856977463, total_time: 0.223697900772, absolute_episode: [], quality: 720p HDTV, episode: [], season: None
2017-03-17 02:01:17 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match At.Midnight.2017.03.15.1080p.WEB.x264-HEAT to a show in your database. Parser result: title: At Midnight, date: 2017-03-15, screen_size: 1080p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: HEAT, type: episode, parsing_time: 0.223325014114, total_time: 0.227200031281, absolute_episode: [], quality: 1080p WEB-DL, episode: [], season: None
2017-03-17 02:01:18 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Descending.Stories.Showa.Genroku.Rakugo.Shinju.S01E10.1080p.WEB.x264-ANiURL to a show in your database. Parser result: title: Descending Stories Showa Genroku Rakugo Shinju, season: 1, episode: [10], screen_size: 1080p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: ANiURL, type: episode, parsing_time: 0.198397874832, total_time: 0.558728933334, absolute_episode: [], quality: 1080p WEB-DL
2017-03-17 02:01:18 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match The.Americans.2013.S05E02.Pests.1080p.AMZN.WEBRip.DD5.1.x264-NTb.mkv to a show in your database. Parser result: title: The Americans, alias: The Americans 2013, year: 2013, season: 5, episode: [2], episode_title: Pests, screen_size: 1080p, streaming_service: Amazon Prime, format: WEBRip, audio_codec: AC3, audio_channels: 5.1, video_codec: h264, video_encoder: x264, release_group: NTb, container: mkv, mimetype: video/x-matroska, type: episode, parsing_time: 0.318644046783, total_time: 0.679970979691, absolute_episode: [], quality: 1080p WEB-DL
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Scene numbering enabled show 'Snatch' using indexer numbering: S01E02
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Converted parsed result Snatch.S01E02.1080p.WEB.X264-DEFLATE into title: Snatch, season: 1, episode: [2], screen_size: 1080p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: DEFLATE, type: episode, parsing_time: 0.193113088608, total_time: None, absolute_episode: [], quality: 1080p WEB-DL
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Matched release 'Snatch.S01E02.1080p.WEB.X264-DEFLATE' to a show in your database: 'Snatch'
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Parsed 'Snatch.S01E02.1080p.WEB.X264-DEFLATE' into title: Snatch, season: 1, episode: [2], screen_size: 1080p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: DEFLATE, type: episode, parsing_time: 0.193113088608, total_time: 0.200086116791, absolute_episode: [], quality: 1080p WEB-DL
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Added RSS item: [Snatch.S01E02.1080p.WEB.X264-DEFLATE] to cache: [bithdtv]
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Bellevue.S01E04.INTERNAL.720p.HDTV.x264-aAF to a show in your database. Parser result: title: Bellevue, season: 1, episode: [4], other: Internal, screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: aAF, type: episode, parsing_time: 0.189285993576, total_time: 0.541562795639, absolute_episode: [], quality: 720p HDTV
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Seth.Meyers.2017.03.15.Keri.Russell.720p.WEB.x264-HEAT to a show in your database. Parser result: title: Seth Meyers, date: 2017-03-15, episode_title: Keri Russell, screen_size: 720p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: HEAT, type: episode, parsing_time: 0.221376895905, total_time: 0.225260019302, absolute_episode: [], quality: 720p WEB-DL, episode: [], season: None
2017-03-17 02:01:20 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Arrow.S05E16.Checkmate.1080p.WEBRip.DD5.1.x264-CasStudio.mkv to a show in your database. Parser result: title: Arrow, season: 5, episode: [16], episode_title: Checkmate, screen_size: 1080p, format: WEBRip, audio_codec: AC3, audio_channels: 5.1, video_codec: h264, video_encoder: x264, release_group: CasStudio, container: mkv, mimetype: video/x-matroska, type: episode, parsing_time: 0.257858991623, total_time: 0.618865013123, absolute_episode: [], quality: 1080p WEB-DL
2017-03-17 02:01:21 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Jeff.And.Some.Aliens.S01E10.720p.HDTV.x264-MiNDTHEGAP to a show in your database. Parser result: title: Jeff And Some Aliens, season: 1, episode: [10], screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: MiNDTHEGAP, type: episode, parsing_time: 0.190773963928, total_time: 0.556802988052, absolute_episode: [], quality: 720p HDTV
2017-03-17 02:01:21 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Greys.Anatomy.S13E16.720p.HDTV.X264-DIMENSION to a show in your database. Parser result: title: Greys Anatomy, season: 13, episode: [16], screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: DIMENSION, type: episode, parsing_time: 0.181162118912, total_time: 0.184938192368, absolute_episode: [], quality: 720p HDTV
2017-03-17 02:01:21 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Bellevue.S01E03.INTERNAL.720p.HDTV.x264-aAF to a show in your database. Parser result: title: Bellevue, season: 1, episode: [3], other: Internal, screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: aAF, type: episode, parsing_time: 0.18679690361, total_time: 0.549944877625, absolute_episode: [], quality: 720p HDTV
2017-03-17 02:01:22 ERROR    SHOWUPDATER :: [a70a6df] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show Hannibal. Cause: 'NoneType' object is not iterable.
Traceback (most recent call last):
  File "/home/pi/Medusa/medusa/show_updater.py", line 86, in run
    update_max_weeks)
  File "/home/pi/Medusa/medusa/indexers/tvdbv2/tvdbv2_api.py", line 565, in get_last_updated_series
    last_update_ts = max(x.last_updated for x in updates)
TypeError: 'NoneType' object is not iterable

# 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.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, MaxRetryError, RequestError) as e:
        raise IndexerUnavailable(
            "Error connecting to Tvdb api. Caused by: {0!r}".format(e)
        )

    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