Example #1
0
    def check_episodes_download(self):
        """Return tuple with episodes that are airing today.

        The TVMaze API's "episodesbydate" returns info about which
        episodes are airing today. We append every episode that aired
        to the "new_episodes" list in form of a tuple containing
        the show's title, season and episode number.

        If Show.delay is True, we have to pass yesterday's date to
        the API query to get yesterday's results today.
        """
        if Show.delay:
            date = TODAY - datetime.timedelta(days=1)
        else:
            date = TODAY

        self.fetch_show_info()
        show_id = self.info["id"]

        search_query = "{}/shows/{}/episodesbydate?date={}".format(
            API_URL,
            show_id,
            date.isoformat()
            )
        response = utils.get_URL_string(search_query)
        info = json.loads(response)

        new_episodes = []
        for new_episode in info:
            new_episodes.append(
                (self.title, new_episode["season"], new_episode["number"])
                )

        return new_episodes
Example #2
0
    def fetch_show_info(self):
        """Download information about the show.

        Uses the TVMaze API to get various data about the show.
        The main endpoint is "singlesearch", but with embedded
        "season" and "episodes" information.

        If no show with the name can be found, self.info will be None.
        """
        API_endpoint = "/singlesearch/shows?q="
        API_embedded = "&embed[]=seasons&embed[]=episodes"
        search_query = "{}{}{}{}".format(
            API_URL,
            API_endpoint,
            self.title,
            API_embedded
            )
        response = utils.get_URL_string(search_query)
        if response:
            self.info = json.loads(response)