From 1fc2d55983da0dcc196ecde61966dffdc3232676 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Mon, 4 Sep 2023 22:44:00 +0200 Subject: [PATCH] cleanup --- hn.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/hn.py b/hn.py index c0c76f7..d883700 100755 --- a/hn.py +++ b/hn.py @@ -89,8 +89,10 @@ class Client: page = int(self.story_pos / self.stories_in_a_site + 1) total_pages = math.ceil(500/len(self.loadedstories)) - self.set_footer(f'Page {page}/{total_pages}, loaded {len(self.loadedstories)} stories.') - #self.set_footer(f'{self.loadedstories}') + footer_text = f'Page {page}/{total_pages}, loaded {len(self.loadedstories)} stories. [?] for help.' + if len(footer_text) >= self.cols: + footer_text = footer_text[:self.cols - 1] + self.set_footer(footer_text) async def handle_input(self): c = self.screen.getch() @@ -141,7 +143,7 @@ class Client: def help(self): def __helpwin_addstr__(win, string, newline=True): - c_pos_y, c_pos_x = win.getyx() + c_pos_y, _ = win.getyx() win.move(c_pos_y, 1) win.addstr(string) if newline: @@ -167,14 +169,12 @@ class Client: await self.load_stories(self.story_pos, self.story_pos + self.stories_in_a_site) async def load_stories(self, from_pos, to_pos): - #self.set_footer(f'[{spinner_states[idx%4]}] Loading { to_pos - from_pos } stories...') self.set_footer(f'Loading stories...') self.screen.refresh() story_list = [] tasks = [] - #async with self.session as session: session = self.session - for idx, i in enumerate(self.topstories[from_pos:to_pos]): + for i in self.topstories[from_pos:to_pos]: tasks.append(asyncio.ensure_future(api.get_story(session, i))) story_list = await asyncio.gather(*tasks) for story in story_list: @@ -204,7 +204,6 @@ class Client: self.set_footer("Reloading...") self.screen.refresh() self.topstories = api.get_topstories() - #self.loadedstories = [] self.story_pos = 0 self.cursor_pos = 0 await self.load_stories(self.cursor_pos, self.cursor_pos + self.stories_in_a_site) @@ -212,7 +211,6 @@ class Client: def main(): try: client = Client() - #async with client.run(): asyncio.run(client.run()) except Exception as e: curses.endwin()