def create_new_cache(self, name):
     today_date = get_todays_date()
     self.my_history = {
         'version': self.cache_version,
         'name': name,
         'skipped': [],
         'episodes': [],
         'latest_season': 0,
         'next_check': today_date,
         'last_check': today_date,
         'log_msg': ''}
    def set_next_check(self, next_aired, last_aired, status):
        """ Set the next check date for this show based on next/last aired and status """
        if next_aired and next_aired.get('air_date'):
            next_aired_dt = next_aired.get('air_date')
            if is_future_timestamp(next_aired_dt, "%Y-%m-%d", 10):
                if not is_future_timestamp(
                        next_aired_dt, "%Y-%m-%d", 10, days=7):
                    self.my_history['next_check'] = next_aired.get('air_date')
                    self.my_history[
                        'log_msg'] = 'Show had next aired date this week'
                    # Check again on the next aired date
                elif not is_future_timestamp(
                        next_aired_dt, "%Y-%m-%d", 10, days=30):
                    self.my_history['next_check'] = get_todays_date(days=7)
                    self.my_history[
                        'log_msg'] = 'Show has next aired date this month'
                    # Check again in a week just to be safe in case air date changes
                else:
                    self.my_history['next_check'] = get_todays_date(days=30)
                    self.my_history[
                        'log_msg'] = 'Show has next aired date in more than a month'
                    # Check again in a month just to be safe in case air date changes
            else:
                next_aired = None  # Next aired was in the past for some reason so dont use that date

        if not next_aired and last_aired and last_aired.get('air_date'):
            last_aired_dt = last_aired.get('air_date')
            if is_future_timestamp(last_aired_dt, "%Y-%m-%d", 10, days=-30):
                self.my_history['next_check'] = get_todays_date(days=1)
                self.my_history[
                    'log_msg'] = 'Show aired in last month but no next aired date'
                # Show might be currently airing but just hasnt updated next date yet so check again tomorrow
            elif is_future_timestamp(last_aired_dt, "%Y-%m-%d", 10, days=-90):
                self.my_history[
                    'log_msg'] = 'Show aired in last quarter but not in last month'
                self.my_history['next_check'] = get_todays_date(days=7)
                # Show might be on a mid-season break so check again in a week for a return date
            elif status in ['Canceled', 'Ended']:
                self.my_history['log_msg'] = 'Show was canceled or ended'
                self.my_history['next_check'] = get_todays_date(days=30)
                # Show was canceled so check again in a month just to be safe
            else:
                self.my_history[
                    'log_msg'] = 'Show last aired more than 3 months ago and no next aired date set'
                self.my_history['next_check'] = get_todays_date(days=7)
 def _out(self):  # TODO: Check logging value
     filename = u'{}.json'.format(
         get_todays_date(str_fmt='%Y-%m-%d-%H%M%S'))
     dumps_to_file(self.logging, 'log_library', filename)