Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add an option to print URLs

  This makes it possible to jump to stories directly from the terminal
  • Loading branch information...
commit 2e4e12ffb323dc4acbc21de58b928133e2b60405 1 parent aea0ffa
@eschulte eschulte authored
Showing with 26 additions and 3 deletions.
  1. +4 −1 README.txt
  2. +22 −2 hacker_top
View
5 README.txt
@@ -48,7 +48,7 @@ See my original article for a screenshot:
Usage: ./hacker_top.py [-h|--help] - displays help message
Usage: ./hacker_top.py [-i|--interval interval]
- [-u|--utf8 <on|off>] [-n|--new]
+ [-u|--utf8 <on|off>] [-U|--url <on|off>] [-n|--new]
-i or --interval specifies refresh interval.
The default refresh interval is 3 minutes. Here are a few
@@ -58,6 +58,9 @@ Usage: ./hacker_top.py [-i|--interval interval]
Default: off. Use this if you know for sure that your
terminal supports it, otherwise your terminal might turn into garbage.
+ -U or --url turns on printing of urls.
+ Default: off
+
-n or --new follows only the newest hacker stories.
Default: follow front page stories.
View
24 hacker_top
@@ -39,6 +39,9 @@ default_interval = '3m'
# Change with -u|--utf command option
default_can_utf8 = False
+# Do we want to show urls
+default_show_url = False
+
# Monitor new stories?
default_new = False
@@ -204,8 +207,20 @@ class BasicDisplay(DisplayMode):
def do_display(self, story):
title_line = self.format_title(story)
self.display_title(title_line)
+ if interface.show_url:
+ self.display_url(story)
self.display_info(story)
+ def display_url(self, story):
+ url = html_unescape(story.url)
+ if len(url) > (self.interface.body_max_x - 4):
+ url = url[:self.interface.body_max_x-8] + "..."
+ if not interface.can_utf8:
+ url = story.url.decode('utf8').encode('ascii', 'replace')
+ self.interface.body_win.addstr(" ")
+ self.interface.body_win.addstr(url[:4])
+ self.interface.body_win.addstr(url[4:] + "\n")
+
def display_title(self, title_line):
self.interface.body_win.addstr(title_line[:4])
self.interface.body_win.addstr(title_line[4:] + "\n", curses.color_pair(1))
@@ -339,6 +354,7 @@ class Interface(object):
def __init__(self, args):
self.update_secs = Interval(args['interval']).to_secs()
self.can_utf8 = args['utf8']
+ self.show_url = args['url']
self.new = args['new']
self.pages_changed = True
self.pages = 1
@@ -612,13 +628,14 @@ def parse_args(args):
ps. i don't like optparse. """
try:
- opts = getopt.getopt(args, "i:unh", ['interval=', 'utf8', 'new', 'help'])[0]
+ opts = getopt.getopt(args, "i:uUnh", ['interval=', 'utf8', 'url', 'new', 'help'])[0]
except getopt.GetoptError, e:
raise ArgError, str(e)
return_args = {
'interval': default_interval,
'utf8': default_can_utf8,
+ 'url': default_show_url,
'new': default_new
}
@@ -633,6 +650,8 @@ def parse_args(args):
raise ArgError, e
elif opt in ("-u", "--utf8"):
return_args['utf8'] = True
+ elif opt in ("-U", "--url"):
+ return_args['url'] = True
elif opt in ("-n", "--new"):
return_args['new'] = True
else:
@@ -654,13 +673,14 @@ def print_head():
def print_usage():
print "Usage: %s [-h|--help] - displays this" % sys.argv[0]
print "Usage: %s [-i|--interval interval] [-u|--utf8 <on|off>]" % sys.argv[0]
- print " [-n|--new]"
+ print " [-n|--new] [-u|--utf8 <on|off>] [-U|--url <on|off>]"
print
print "-i|--interval specifies refresh interval."
print " Valid examples: 10s (10 seconds), 12m (12 minutes), 42h (42 hours)."
print " Default: %s" % default_interval
print "-u|--utf8 turns on utf8 output mode. Use this if you know for sure that"
print " your terminal supports it. Default: %s" % str(default_can_utf8)
+ print "-U|--url print url. Default: %s" % str(default_show_url)
print "-n|--new specifies that new stories only should be monitored"
print " Default: %s" % default_new
Please sign in to comment.
Something went wrong with that request. Please try again.