def __init__(self, title, season, premiere, end, episodes): self.title = title self.season = season self.premiere = utils.date_from_string(premiere, Show.delay) self.end = utils.date_from_string(end, Show.delay) self.episodes = self.episodes_to_date(episodes) self.info = None self.last_episode = None self.get_status() self.get_last_episode()
def get_premiere(self): """Get the season's premiere date. Inside the "_embedded" data is information about the seasons. We want the value of the "premiereDate" key of the current season. Since seasons are indexed by 0 in the list, we have to subtract 1 from our actual season number while accessing the key's value. """ premiere = self.info["_embedded"]["seasons"][self.season - 1]["premiereDate"] self.premiere = utils.date_from_string(premiere, Show.delay)
def get_end(self): """Get the current season's end date. Inside the "_embedded" data is information about the seasons. We want the value of the "endDate" key of the current season. Since seasons are indexed by 0 in the list, we have to subtract 1 from our actual season number while accessing the key's value. """ end = self.info["_embedded"]["seasons"][self.season - 1]["endDate"] self.end = utils.date_from_string(end, Show.delay)
def episodes_to_date(self, dictionary): """Returns a dictionary with proper dateobjects. Takes a dictionary as an argument (the episodes dictionary which contains episode number and airing date pairs). Goes through each date (which is a string in the initial dict) and creates a dateobject from it. It appends each key,value pair to a new dictionary and returns it. """ new_dictionary = {} for number, date in dictionary.items(): new_dictionary[number] = utils.date_from_string(date, Show.delay) return new_dictionary