read status, eyecandy

This commit is contained in:
Felix Pankratz 2023-08-29 23:01:30 +02:00
parent 0e590eefed
commit edeeb793ff

21
hn.py
View File

@ -1,10 +1,5 @@
#!/usr/bin/env python3
#TODO: make sure things dont explode no matter what terminal size
# x prevent linebreaks in a single story
# x only load as many stories as fit
# -> refresh on resize
import requests
from bs4 import BeautifulSoup as Soup
import curses
@ -72,12 +67,18 @@ class Client:
self.screen.addstr(prefix)
if i == self.cursor_pos:
self.screen.addstr(title, curses.A_UNDERLINE)
if story.read:
self.screen.addstr(title, curses.A_DIM | curses.A_UNDERLINE)
else:
self.screen.addstr(title, curses.A_UNDERLINE)
self.screen.addstr(f' ({link})\n', curses.A_DIM )
detail = f' by {story.author} | {story.comments} comments | {story.votes} points\n'
self.screen.addstr(detail)
else:
self.screen.addstr(title)
if story.read:
self.screen.addstr(title, curses.A_DIM)
else:
self.screen.addstr(title)
self.screen.addstr(f' ({link})\n', curses.A_DIM )
page = int(self.story_pos / self.stories_in_a_site + 1)
@ -107,7 +108,11 @@ class Client:
elif c == ord('c'):
webbrowser.open(f'https://news.ycombinator.com/item?id={self.loadedstories[self.story_pos + self.cursor_pos].id}')
elif c == curses.KEY_ENTER or c == 10:
webbrowser.open(self.loadedstories[self.story_pos + self.cursor_pos].link)
if self.loadedstories[self.story_pos + self.cursor_pos].link == 'No URL':
webbrowser.open(f'https://news.ycombinator.com/item?id={self.loadedstories[self.story_pos + self.cursor_pos].id}')
else:
webbrowser.open(self.loadedstories[self.story_pos + self.cursor_pos].link)
self.loadedstories[self.story_pos + self.cursor_pos].read = True
elif c == curses.KEY_RESIZE:
curses.resize_term(*self.screen.getmaxyx())
self.lines, self.cols = self.screen.getmaxyx()