def time_tracking(self): end_time = time.time() time_watched = end_time - self.start_time database_instance = twitchy_database.DatabaseFunctions() def fetch_time_data(): # Even for a non watched channel, the database # always has a 0 value associated # Therefore, there will be no None returns time_watched_channel = database_instance.fetch_data( ('TimeWatched',), 'channels', {'Name': self.channel_name}, 'EQUALS', True) time_watched_game = database_instance.fetch_data( ('TimeWatched',), 'games', {'Name': self.channel_params['game']}, 'EQUALS', True) return time_watched_channel, time_watched_game time_data = fetch_time_data() time_values = { 'channel_name': self.channel_name, 'new_time_channel': time_data[0] + time_watched, 'game_name': self.channel_params['game'], 'new_time_game': time_data[1] + time_watched} database_instance.modify_data( 'update_time', None, time_values) time_data_new = fetch_time_data() game_display_name = self.channel_params['game_display_name'] if not game_display_name: game_display_name = self.channel_params['game'] channel_rank = get_rank_data('channels', self.channel_name) if channel_rank: channel_rank = ' (' + channel_rank + ')' game_rank = get_rank_data('games', self.channel_params['game']) if game_rank: game_rank = ' (' + game_rank + ')' # Consider shfting this to the main module if twitchy_config.print_to_stdout: print( ' ' + Colors.WHITE + self.channel_params['display_name'] + ': ' + Colors.ENDC + time_convert(time_data_new[0]) + channel_rank + ' | ' + Colors.WHITE + game_display_name + ': ' + Colors.ENDC + time_convert(time_data_new[1]) + game_rank)
def non_interactive(mode, channel_name=None): if mode == 'get_online': # Output format: # Game name, Game display name (if present)... # Channel name, Channel display name (always present) channel_data = database_instance.fetch_data(('ChannelID', ), 'channels', None, 'LIKE') id_string_list = [str(i[0]) for i in channel_data] channels_online = twitchy_api.GetOnlineStatus( id_string_list).check_channels() # All standard channel parameters are available for i in channels_online.items(): return_list = [] config_correlate = { 'GameName': i[1]['game'], 'GameAltName': str(i[1]['game_display_name']), 'ChannelName': i[0], 'ChannelAltName': i[1]['display_name'], 'Status': i[1]['status'], 'Viewers': str(i[1]['viewers']), 'Uptime': twitchy_display.time_convert(i[1]['uptime']) } for j in Options.non_int_display_scheme: return_list.append(config_correlate[j]) print(Options.non_int_delimiter.join(return_list)) if mode == 'kickstart': # Skip selection and just pass the channel name to the play module # All output is disabled except for error messages # Time tracking is disabled twitchy_config.print_to_stdout = False twitchy_config.time_tracking = False twitchy_config.non_interactive_mode = True if not channel_name: exit(1) try: api_reply = twitchy_api.name_id_translate('channels', 'id_from_name', [channel_name]) channel_id = api_reply[channel_name]['id'] channel_status = twitchy_api.GetOnlineStatus([channel_id ]).check_channels() # The video is started in default quality channel_status[channel_name][ 'quality'] = Options.video.default_quality twitchy_play.play_instance_generator(channel_status) except KeyError: exit()