def is_active(asset): """Accepts an asset dictionary and determines if it is active, returning Boolean.""" if not (asset['start_date'] and asset['end_date']): return False if asset['start_date'] < get_current_time() and asset['end_date'] > get_current_time(): return True else: return False
def generate_asset_list(): logging.info('Generating asset-list...') c = connection.cursor() c.execute("SELECT asset_id, name, uri, md5, start_date, end_date, duration, mimetype FROM assets ORDER BY name") query = c.fetchall() playlist = [] time_cur = get_current_time() deadline = None for asset in query: asset_id = asset[0] name = asset[1].encode('ascii', 'ignore') uri = asset[2] md5 = asset[3] start_date = asset[4] end_date = asset[5] duration = asset[6] mimetype = asset[7] logging.debug('generate_asset_list: %s: start (%s) end (%s)' % (name, start_date, end_date)) if start_date and end_date: if start_date < time_cur and end_date > time_cur: playlist.append({"asset_id": asset_id, "name": name, "uri": uri, "duration": duration, "mimetype": mimetype}) if not deadline or end_date < deadline: deadline = end_date elif start_date >= time_cur and end_date > start_date: if not deadline or start_date < deadline: deadline = start_date logging.debug('generate_asset_list deadline: %s' % deadline) if settings.shuffle_playlist: shuffle(playlist) return (playlist, deadline)
def refresh_playlist(self): logging.debug('refresh_playlist') time_cur = get_current_time() logging.debug('refresh: counter: (%d) deadline (%s) timecur (%s)' % (self.counter, self.deadline, time_cur)) if self.dbisnewer(): self.update_playlist() elif settings.shuffle_playlist and self.counter >= 5: self.update_playlist() elif self.deadline and self.deadline <= time_cur: self.update_playlist()
def get_playlist(): c = connection.cursor() c.execute("SELECT * FROM assets ORDER BY name") assets = c.fetchall() playlist = [] for asset in assets: # Match variables with database asset_id = asset[0] name = asset[1] uri = asset[2] # Path in local database input_start_date = asset[4] input_end_date = asset[5] try: start_date = datestring.date_to_string(asset[4]) except: start_date = None try: end_date = datestring.date_to_string(asset[5]) except: end_date = None if (start_date and end_date) and (input_start_date < get_current_time() and input_end_date > get_current_time()): duration = asset[6] mimetype = asset[7] playlistitem = { "name": name, "uri": uri, "duration": duration, "mimetype": mimetype, "asset_id": asset_id, "start_date": start_date, "end_date": end_date } playlist.append(playlistitem) return playlist
def is_active(asset, at_time=None): """Accepts an asset dictionary and determines if it is active at the given time. If no time is specified, get_current_time() is used. >>> asset = {'asset_id': u'4c8dbce552edb5812d3a866cfe5f159d', 'mimetype': u'web', 'name': u'WireLoad', 'end_date': datetime(2013, 1, 19, 23, 59), 'uri': u'http://www.wireload.net', 'duration': u'5', 'start_date': datetime(2013, 1, 16, 0, 0)}; >>> is_active(asset, datetime(2013, 1, 16, 12, 00)) True >>> is_active(asset, datetime(2014, 1, 1)) False """ if not (asset['start_date'] and asset['end_date']): return False at_time = at_time or get_current_time() return (asset['start_date'] < at_time and asset['end_date'] > at_time)