Exemplo n.º 1
0
    def update(self):
        """Get the latest state of the sensor."""
        from trakt.calendar import MyShowCalendar
        calendar = MyShowCalendar(days=self._days)

        if not calendar:
            _LOGGER.error("Nothing in calendar")
            return False

        self._state = len(calendar)

        for show in calendar:
            if not show:
                continue

            self._hass.data[DATA_UPCOMING][xstr(show.show) + ' - ' +
                                           xstr(show.title)] = {
                                               "show": xstr(show.show),
                                               "title": xstr(show.title),
                                               "season": xstr(show.season),
                                               "number": xstr(show.number),
                                               "overview": xstr(show.overview),
                                               "airs_at": xstr(show.airs_at),
                                               "trakt_id": xstr(show.trakt),
                                               "tmdb_id": xstr(show.tmdb),
                                               "tvdb_id": xstr(show.tvdb),
                                               "imdb_id": xstr(show.imdb),
                                           }
Exemplo n.º 2
0
def test_my_shows():
    """functional tests for the :class:`MyShowCalendar` class"""
    date, days = '2014-09-01', 7
    cal = MyShowCalendar(date=date, days=days)
    assert isinstance(cal, MyShowCalendar)
    assert cal.days == days
    assert cal.date == date
    assert len(cal) == 4
Exemplo n.º 3
0
    def update(self):
        """Get the latest state of the sensor."""
        from trakt.calendar import MyShowCalendar
        from trakt.tv import TVShow
        import requests
        attributes = {}
        default = {}
        card_json = []
        default['title_default'] = '$title'
        default['line1_default'] = '$episode'
        default['line2_default'] = '$release'
        default['line3_default'] = '$rating - $runtime'
        default['line4_default'] = '$number - $studio'
        default['icon'] = 'mdi:arrow-down-bold'
        card_json.append(default)
        calendar = MyShowCalendar(days=self._days)

        if not calendar:
            _LOGGER.error("Nothing in upcoming calendar")
            return False

        self._state = len(calendar)

        for show in calendar:
            if not show or show.show in self._exclude:
                continue

            try:
                show_details = TVShow.search(show.show, show.year)
            except AttributeError:
                _LOGGER.error('Unable to retrieve show details for ' +
                              show.show)

            if not show_details:
                continue

            session = requests.Session()
            try:
                tmdb_url = session.get(
                    'http://api.tmdb.org/3/tv/{}?api_key=0eee347e2333d7a97b724106353ca42f'
                    .format(str(show_details[0].tmdb)))
                tmdb_json = tmdb_url.json()
            except requests.exceptions.RequestException as e:
                _LOGGER.warning('api.themoviedb.org is not responding')
                return
            image_url = 'https://image.tmdb.org/t/p/w%s%s'
            if days_until(show.airs_at.isoformat() + 'Z', self._tz) <= 7:
                release = '$day, $time'
            else:
                release = '$day, $date $time'

            card_item = {
                'airdate':
                show.airs_at.isoformat() + 'Z',
                'release':
                release,
                'flag':
                False,
                'title':
                show.show,
                'episode':
                show.title,
                'number':
                'S' + str(show.season) + 'E' + str(show.number),
                'rating':
                tmdb_json.get('vote_average', ''),
                'poster':
                image_url % ('500', tmdb_json.get('poster_path', '')),
                'fanart':
                image_url % ('780', tmdb_json.get('backdrop_path', '')),
                'runtime':
                tmdb_json.get('episode_run_time')[0]
                if len(tmdb_json.get('episode_run_time')) > 0 else '',
                'studio':
                tmdb_json.get('networks')[0].get('name', '')
                if len(tmdb_json.get('networks')) > 0 else ''
            }
            card_json.append(card_item)

        attributes['data'] = json.dumps(card_json)
        self._hass.data[DATA_UPCOMING] = attributes