def change_date(self, btn): def destroy(): # removes pop-up self.app.loop.widget = self.app.frame # get the ids for given day _ids = get_game_ids(params={'date': str(btn.data.get_date())}) self.app.banner_games = asyncio.run( batch_game_create(_ids, 'banner', self.app.db_conn)) self.app.size = len(self.app.banner_games) # populates deques self.app._populate_hidden() self._update_in_place(btn.data) destroy()
def __init__(self): self.db_conn = connect_db() _ids = get_game_ids() self.size = len(_ids) self.banner_games = asyncio.run( batch_game_create(_ids, 'banner', self.db_conn)) # sizing self.screen = urwid.raw_display.Screen() (self.cols, self.rows) = self.screen.get_cols_rows() self._sizing() # footer and progress bar self.header = urwid.WidgetPlaceholder(create_header()) # top bar self._populate_hidden() self.game_panel = GamePanel(self, self.tb_rows) self.main_menu = create_main_menu(self, self.tb_rows) self.top_bar = urwid.Columns( [('weight', 1, self.main_menu), ('weight', 4, self.game_panel)], dividechars=1, ) # main display self.context = None self.context_menu = create_opening_menu(self.main_rows) self.display = create_opening_page(self.main_rows) self.main_display = urwid.Columns([('weight', 1, self.context_menu), ('weight', 4, self.display)], dividechars=1) self.list_walk = urwid.SimpleFocusListWalker( [self.top_bar, self.main_display]) self.body = urwid.ListBox(self.list_walk) self.frame = urwid.Frame(urwid.AttrWrap(self.body, 'main'), header=urwid.AttrWrap(self.header, 'main')) self.loop = urwid.MainLoop(self.frame, palette=PALETTE, screen=self.screen, pop_ups=True)
def change_date(self, btn): """Change the box score display to the provided date.""" date = btn.data.get_date() if date == self.display_date: self.app.destroy() return else: self.display_date = date _ids = get_game_ids(params={'date': str(date)}) self.size = len(_ids) self.full_games = asyncio.run( utils.batch_game_create(_ids, 'full', self.app.db_conn) ) self._update_in_place() self.app.destroy()
def __init__(self, app, ctx, rows): BaseDisplay.__init__(self, app, ctx, rows) _ids = get_game_ids() # number of games self.size = len(_ids) # list of game objects self.full_games = asyncio.run( utils.batch_game_create(_ids, 'full', self.app.db_conn) ) # date of games on display self.display_date = arrow.now().date() widget = self.main_display() # Cannot copy full_games because of connection data. # Until a workaround is found just request data twice. self.todays_games = asyncio.run( utils.batch_game_create(_ids, 'full', self.app.db_conn) ) urwid.WidgetWrap.__init__(self, widget)
def _request_games(self): """Request the current weeks games.""" # clear the dictionary to start fresh self.current_week_games.clear() start = self.current_week_start.date() end = self.current_week_end.date() # NOTE: a batch request for ALL dates is chosen because the speed # gain is much better than individual requesting each day of the week _ids = get_game_ids( params={ 'startDate': str(start), 'endDate': str(end) } ) games = asyncio.run( utils.batch_game_create(_ids, 'banner', self.app.db_conn) ) # this partitions games by their date for game in games: self.current_week_games[game.game_date].append(game)
def normal_games_echo(db_conn, params=None): game_ids = get_game_ids(params=params) games_list = asyncio.run(batch_game_create(game_ids, 'banner', db_conn)) build_norm_output(games_list)