remove protocols from urls before displaying

master
Felix Pankratz 1 year ago
parent 23fb38b807
commit 67136668f4

@ -54,14 +54,17 @@ def main(stdscr):
stdscr.addstr('Hacker News Top Stories:\n')
for i, story in enumerate(stories):
prefix = '>>> ' if i == current_pos else ' '
#text = f'{prefix}{story.title} ({story.link})\n'
# calculate length of line
text = f'{prefix} ()\n'
chars_available = width - len(text)
max_title_len = min((chars_available//3)*2, len(story.title))
max_url_len = chars_available - max_title_len
title = story.title[:max_title_len-1] + "" if len(story.title) > max_title_len else story.title
link = story.link.replace('https://', '').replace('http://', '')
link = link[:max_url_len-1] + "" if len(link) > max_url_len else link
text = f'{prefix}{(story.title[:max_title_len-1] + "") if len(story.title) > max_title_len else story.title} ({story.link[:max_url_len-1] + "" if len(story.link) > max_url_len else story.link})\n'
text = '{}{} ({})\n'.format(prefix, title, link.replace('https://', '').replace('http://', ''))
stdscr.addstr(text)
if i == current_pos:
detail = f' by {story.author} | {story.comments} comments | {story.votes} points\n'
@ -82,8 +85,6 @@ def main(stdscr):
elif c == ord('c'):
webbrowser.open(f'https://news.ycombinator.com/item?id={stories[current_pos].id}')
elif c == curses.KEY_ENTER or c == 10:
#title, link = stories[current_pos]
#print(f'\nOpening link: {link}\n')
webbrowser.open(stories[current_pos].link)
curses.wrapper(main)

Loading…
Cancel
Save