|
|
@ -13,6 +13,7 @@ class Story:
|
|
|
|
link: str
|
|
|
|
link: str
|
|
|
|
author: str
|
|
|
|
author: str
|
|
|
|
votes: int
|
|
|
|
votes: int
|
|
|
|
|
|
|
|
comments: int
|
|
|
|
|
|
|
|
|
|
|
|
def main(stdscr):
|
|
|
|
def main(stdscr):
|
|
|
|
stdscr.clear()
|
|
|
|
stdscr.clear()
|
|
|
@ -27,10 +28,11 @@ def main(stdscr):
|
|
|
|
for i in ids:
|
|
|
|
for i in ids:
|
|
|
|
story_url = f'https://hacker-news.firebaseio.com/v0/item/{i}.json'
|
|
|
|
story_url = f'https://hacker-news.firebaseio.com/v0/item/{i}.json'
|
|
|
|
s = requests.get(story_url).json()
|
|
|
|
s = requests.get(story_url).json()
|
|
|
|
try:
|
|
|
|
stories.append(Story(s['id'],
|
|
|
|
stories.append(Story(s['id'], s['title'], s['url'], s['by'], s['score']))
|
|
|
|
s['title'],
|
|
|
|
except KeyError:
|
|
|
|
s['url'] if 'url' in s else 'No URL',
|
|
|
|
stories.append(Story(s['id'], s['title'], 'No URL', s['by'], s['score']))
|
|
|
|
s['by'], s['score'],
|
|
|
|
|
|
|
|
len(s['kids']) if 'kids' in s else 0))
|
|
|
|
|
|
|
|
|
|
|
|
# Display list of stories in terminal window with arrow key navigation
|
|
|
|
# Display list of stories in terminal window with arrow key navigation
|
|
|
|
current_pos = 0
|
|
|
|
current_pos = 0
|
|
|
@ -42,7 +44,7 @@ def main(stdscr):
|
|
|
|
text = f'{prefix}{story.title} ({story.link})\n'
|
|
|
|
text = f'{prefix}{story.title} ({story.link})\n'
|
|
|
|
stdscr.addstr(text)
|
|
|
|
stdscr.addstr(text)
|
|
|
|
if i == current_pos:
|
|
|
|
if i == current_pos:
|
|
|
|
detail = f' by {story.author} | {story.votes} points\n'
|
|
|
|
detail = f' by {story.author} | {story.comments} comments | {story.votes} points\n'
|
|
|
|
stdscr.addstr(detail)
|
|
|
|
stdscr.addstr(detail)
|
|
|
|
|
|
|
|
|
|
|
|
stdscr.refresh()
|
|
|
|
stdscr.refresh()
|
|
|
|