Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from eschulte/master

add option to print the url, allowing jumping to stories directly from the command line
  • Loading branch information...
commit d1d1386005b4cbb5a167b2c803de9345dc107f70 2 parents 48850f3 + e1494d9
@pkrumins authored
Showing with 121 additions and 10 deletions.
  1. +41 −0 PKGBUILD
  2. +4 −0 readme.txt
  3. +43 −10 reddit_top.py → reddit_top
  4. +33 −0 setup.py
View
41 PKGBUILD
@@ -0,0 +1,41 @@
+# Maintainer: Nicolas Paris <nicolas.caen@gmail.com>
+pkgname=reddit-top-git
+pkgver=20110707
+pkgrel=1
+pkgdesc="It's a top-like program for monitoring stories on reddit from the console (fork from pkrumins)"
+arch=('any')
+url="https://github.com/Nic0/reddit-top"
+license=('GPL')
+depends=('python2-distribute' 'python-beautifulsoup')
+makedepends=('git')
+
+_gitroot="git://github.com/Nic0/reddit-top.git"
+_gitname="reddit-top"
+
+build() {
+ cd "$srcdir"
+ msg "Connecting to GIT server...."
+
+ if [ -d $_gitname ] ; then
+ cd $_gitname && git pull origin
+ msg "The local files are updated."
+ else
+ git clone $_gitroot $_gitname
+ fi
+
+ msg "GIT checkout done or server timeout"
+ msg "Starting make..."
+
+ rm -rf "$srcdir/$_gitname-build"
+ git clone "$srcdir/$_gitname" "$srcdir/$_gitname-build"
+ cd "$srcdir/$_gitname-build"
+
+ python2 setup.py build
+
+}
+
+package() {
+ cd "$srcdir/$_gitname-build"
+ python2 setup.py install --prefix=/usr --root="$pkgdir"
+}
+
View
4 readme.txt
@@ -56,6 +56,7 @@ Usage: ./reddit_top.py [-h|--help] - displays help message
Usage: ./reddit_top.py [-s|--subreddit subreddit]
[-i|--interval interval]
[-u|--utf8 <on|off>]
+ [-U|--url <on|off>]
[-n|--new]
-s or --subreddit specifies which subreddit to monitor.
@@ -71,6 +72,9 @@ Usage: ./reddit_top.py [-s|--subreddit subreddit]
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 (just submitted) reddit stories.
Default: follow front page stories.
View
53 reddit_top.py → reddit_top
@@ -24,6 +24,7 @@
import termios
import datetime
import threading
+import webbrowser
from htmlentitydefs import entitydefs
from pyredditstories import get_stories, RedesignError, SeriousError, stories_per_page
@@ -43,6 +44,9 @@
# 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
@@ -199,6 +203,8 @@ def display(self, stories):
self.do_display(story)
except IndexError:
break
+ except curses.error:
+ continue
self.interface.body_win.refresh()
@@ -212,8 +218,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))
@@ -347,6 +365,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.subreddit = args['subreddit']
self.pages_changed = True
@@ -365,11 +384,17 @@ def init_and_run(self, stdscr):
except:
pass
- curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
- curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)
- curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK)
- curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK)
- curses.init_pair(5, curses.COLOR_RED, curses.COLOR_BLACK)
+ try:
+ curses.use_default_colors()
+ bgcolor = -1
+ except:
+ bgcolor = curses.COLOR_BLACK
+
+ curses.init_pair(1, curses.COLOR_CYAN, bgcolor)
+ curses.init_pair(2, curses.COLOR_WHITE, bgcolor)
+ curses.init_pair(3, curses.COLOR_GREEN, bgcolor)
+ curses.init_pair(4, curses.COLOR_YELLOW, bgcolor)
+ curses.init_pair(5, curses.COLOR_RED, bgcolor)
self.max_y, self.max_x = stdscr.getmaxyx()
@@ -456,8 +481,8 @@ def run(self):
action.do(self)
except KeyboardInterrupt:
break
- except curses.error, e:
- raise ProgError, "Curses Error: %s" % e
+ #except curses.error, e:
+ #raise ProgError, "Curses Error: %s" % e
def handle_keystroke(self, char):
if char == ord('q'):
@@ -490,6 +515,10 @@ def handle_keystroke(self, char):
self.pages_changed = False
retr_queue_in.put(ChangePages(self.pages))
return
+ elif char == ord('o'):
+ # Open topmost story in webbrrowser (new window)
+ webbrowser.open_new(self.stories[self.start_pos].url)
+ return
elif char == ord('m'):
# Change display mode
self.display_mode += 1
@@ -614,7 +643,7 @@ def parse_args(args):
ps. i don't like optparse. """
try:
- opts = getopt.getopt(args, "s:i:unh", ['subreddit=', 'interval=', 'utf8', 'new', 'help'])[0]
+ opts = getopt.getopt(args, "s:i:uUnh", ['subreddit=', 'interval=', 'utf8', 'url', 'new', 'help'])[0]
except getopt.GetoptError, e:
raise ArgError, str(e)
@@ -622,6 +651,7 @@ def parse_args(args):
'subreddit': default_subreddit,
'interval': default_interval,
'utf8': default_can_utf8,
+ 'url': default_show_url,
'new': default_new
}
@@ -637,7 +667,9 @@ def parse_args(args):
elif opt in ("-s", "--subreddit"):
return_args['subreddit'] = val
elif opt in ("-u", "--utf8"):
- return_args['urf8'] = True
+ return_args['utf8'] = True
+ elif opt in ("-U", "--url"):
+ return_args['url'] = True
elif opt in ("-n", "--new"):
return_args['new'] = True
else:
@@ -659,7 +691,7 @@ def print_head():
def print_usage():
print "Usage: %s [-h|--help] - displays this" % sys.argv[0]
print "Usage: %s [-s|--subreddit subreddit] [-i|--interval interval]" % sys.argv[0]
- print " [-n|--new] [-u|--utf8 <on|off>]"
+ print " [-n|--new] [-u|--utf8 <on|off>] [-U|--url <on|off>]"
print
print "-s|--subreddit specifies the subreddit to monitor,"
print " 'front_page' is a special value which monitors reddit.com front page,"
@@ -670,6 +702,7 @@ def print_usage():
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
View
33 setup.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+"""Handles packaging, distribution, and testing."""
+
+
+#import ez_setup
+#ez_setup.use_setuptools()
+
+from setuptools import setup
+
+
+setup(
+
+# Basic package information.
+name = 'reddit-top',
+version = '1.0',
+scripts = ['reddit_top'],
+py_modules = ['pyredditstories', 'BeautifulSoup'],
+
+# Packaging options.
+zip_safe = False,
+include_package_data = True,
+
+# Metadata for PyPI.
+author = 'Peteris Krumins',
+author_email = 'peter@catonmat.net',
+license = 'GPL',
+url = 'http://www.catonmat.net/blog/follow-hacker-news-from-the-console/',
+keywords = 'hacker news cli',
+description = 'A top-like program for monitoring stories on hacker news.',
+long_description = open('readme.txt').read()
+
+)
+
Please sign in to comment.
Something went wrong with that request. Please try again.