def _translate_discover_params(tmdb_type, params): lookup_keyword = None if params.get('with_id') and params.get('with_id') != 'False' else 'keyword' lookup_company = None if params.get('with_id') and params.get('with_id') != 'False' else 'company' lookup_person = None if params.get('with_id') and params.get('with_id') != 'False' else 'person' lookup_genre = None if params.get('with_id') and params.get('with_id') != 'False' else 'genre' with_separator = params.get('with_separator') if params.get('with_genres'): params['with_genres'] = TMDb().get_translated_list( split_items(params.get('with_genres')), lookup_genre, separator=with_separator) if params.get('without_genres'): params['without_genres'] = TMDb().get_translated_list( split_items(params.get('without_genres')), lookup_genre, separator=with_separator) if params.get('with_keywords'): params['with_keywords'] = TMDb().get_translated_list( split_items(params.get('with_keywords')), lookup_keyword, separator=with_separator) if params.get('without_keywords'): params['without_keywords'] = TMDb().get_translated_list( split_items(params.get('without_keywords')), lookup_keyword, separator=with_separator) if params.get('with_companies'): params['with_companies'] = TMDb().get_translated_list( split_items(params.get('with_companies')), lookup_company, separator='NONE') if params.get('with_people'): params['with_people'] = TMDb().get_translated_list( split_items(params.get('with_people')), lookup_person, separator=with_separator) if params.get('with_cast'): params['with_cast'] = TMDb().get_translated_list( split_items(params.get('with_cast')), lookup_person, separator=with_separator) if params.get('with_crew'): params['with_crew'] = TMDb().get_translated_list( split_items(params.get('with_crew')), lookup_person, separator=with_separator) if params.get('with_release_type'): params['with_release_type'] = TMDb().get_translated_list( split_items(params.get('with_release_type')), None, separator='OR') # Translate relative dates based upon today's date for i in RELATIVE_DATES: datecode = params.get(i, '') datecode = datecode.lower() if not datecode or all(x not in datecode for x in ['t-', 't+']): continue # No value or not a relative date so skip elif 't-' in datecode: days = try_int(datecode.replace('t-', '')) date = get_datetime_now() - get_timedelta(days=days) elif 't+' in datecode: days = try_int(datecode.replace('t+', '')) date = get_datetime_now() + get_timedelta(days=days) params[i] = date.strftime("%Y-%m-%d") return params
def set_cache(my_object, cache_name, cache_days=14, force=False, fallback=None): cache_name = get_pickle_name(cache_name or '') if my_object and cache_name and cache_days: _cache.set('{}.{}'.format(_cache_name, cache_name), my_object, expiration=get_timedelta(days=cache_days)) elif force: my_object = my_object or fallback cache_days = force if isinstance(force, int) else cache_days _cache.set('{}.{}'.format(_cache_name, cache_name), my_object, expiration=get_timedelta(days=cache_days)) return my_object
def set_cache(self, my_object, cache_name, cache_days=14, force=False, fallback=None): self._cache = self._cache or SimpleCache(filename=self._filename, mem_only=self._mem_only) cache_name = get_pickle_name(cache_name or '') if my_object and cache_name and cache_days: self._cache.set(cache_name, my_object, expiration=get_timedelta(days=cache_days)) elif force: my_object = my_object or fallback cache_days = force if isinstance(force, int) else cache_days self._cache.set(cache_name, my_object, expiration=get_timedelta(days=cache_days)) return my_object
def get_calendar_episodes(self, startdate=0, days=1, user=True): # Broaden date range in case utc conversion bumps into different day mod_date = try_int(startdate) - 1 mod_days = try_int(days) + 2 date = get_datetime_today() + get_timedelta(days=mod_date) return self.get_calendar('shows', user, start_date=date.strftime('%Y-%m-%d'), days=mod_days)
def set(self, endpoint, data, checksum="", cache_days=30): ''' set data in cache ''' with self.busy_tasks(u'set.{}'.format(endpoint)): checksum = self._get_checksum(checksum) expires = self._get_timestamp(get_datetime_now() + get_timedelta(days=cache_days)) self._set_mem_cache(endpoint, checksum, expires, data) if not self._mem_only: self._set_db_cache(endpoint, checksum, expires, data)
def _get_basedir_calendar(info=None): items = [] today = get_datetime_today() for i in _get_basedir_calendar_items(): if info not in i['info_types']: continue date = today + get_timedelta( days=i.get('params', {}).get('startdate', 0)) i['label'] = i['label'].format(weekday=date.strftime('%A')) i['params']['info'] = info items.append(i) return items
def run(self): self.xbmc_monitor.waitForAbort(600) # Wait 10 minutes before doing updates to give boot time if self.xbmc_monitor.abortRequested(): del self.xbmc_monitor return self.next_time = get_datetime_combine(get_datetime_today(), get_datetime_time(try_int(self.update_hour))) # Get today at hour self.last_time = xbmc.getInfoLabel('Skin.String(TMDbHelper.AutoUpdate.LastTime)') # Get last update self.last_time = convert_timestamp(self.last_time) if self.last_time else None if self.last_time and self.last_time > self.next_time: self.next_time += get_timedelta(hours=24) # Already updated today so set for tomorrow while not self.xbmc_monitor.abortRequested() and not self.exit and self.poll_time: if ADDON.getSettingBool('library_autoupdate'): if get_datetime_now() > self.next_time: # Scheduled time has past so lets update xbmc.executebuiltin('RunScript(plugin.video.themoviedb.helper,library_autoupdate)') xbmc.executebuiltin('Skin.SetString(TMDbHelper.AutoUpdate.LastTime,{})'.format(get_datetime_now().strftime("%Y-%m-%dT%H:%M:%S"))) self.next_time += get_timedelta(hours=24) # Set next update for tomorrow self.xbmc_monitor.waitForAbort(self.poll_time) del self.xbmc_monitor
def get_daily_list(self, export_list, sorting=None, reverse=False): if not export_list: return datestamp = get_datetime_now() - get_timedelta(days=2) datestamp = datestamp.strftime("%m_%d_%Y") # Pickle results rather than cache due to being such a large list return use_pickle( self._get_downloaded_list, export_list=export_list, sorting=sorting, reverse=reverse, datestamp=datestamp, cache_name=u'TMDb.Downloaded.List.v2.{}.{}.{}'.format( export_list, sorting, reverse, datestamp))
def check_cleanup(self): '''check if cleanup is needed - public method, may be called by calling addon''' if self._mem_only: return cur_time = get_datetime_now() lastexecuted = self._win.getProperty(u"{}.clean.lastexecuted".format( self._sc_name)) if not lastexecuted: self._win.setProperty( u"{}.clean.lastexecuted".format(self._sc_name), repr(tuple(cur_time.timetuple()[:6]))) elif (get_datetime_datetime(*eval(lastexecuted)) + get_timedelta(hours=self._auto_clean_interval)) < cur_time: self._do_cleanup()
def set_pickle(my_object, cache_name, cache_days=14): if not my_object: return cache_name = get_pickle_name(cache_name) if not cache_name: return timestamp = get_datetime_now() + get_timedelta(days=cache_days) cache_obj = { 'my_object': my_object, 'expires': timestamp.strftime("%Y-%m-%dT%H:%M:%S") } with open(os.path.join(_get_write_path('pickle'), cache_name), 'wb') as file: _pickle.dump(cache_obj, file) return my_object