Git Product home page Git Product logo

pyhn's Introduction

Pyhn

Hacker news in your terminal.

image

Don't be worry about your IP. Pyhn is not aggressive, it uses cache.

  • Cache manager
  • Customize all the colors
  • Customize all the keybinds
  • Default vim-like keybindings
  • Compatible with Top, Ask, Show and Job stories
  • Auto refresh support
  • Play nice with tmux and screen (over ssh too!)
  • Open storiers in your commandline web browser
  • Mouse support
  • Easily installable
  • Easily hackable
  • Ultra fast
  • Python 2 and 3
  • MIT license

Installation

Using pip: :

pip install pyhn

Run it: :

pyhn

Arch Linux

pyhn is available in the AUR.

Usage

Use help for all key bindings:

  • h, ?: Print help popup

Configuration

By default, configuration file is in your $HOME/.pyhn/config. You can set key bindings, colors and more.

This is an example file: :

[keybindings]
open_story_link = S,enter
show_story_link = s
open_comments_link = C
show_comments_link = c
open_user_link = U
show_user_link = u
up = j
down = k
page_up = ctrl d
page_down = ctrl u
first_story = g
last_story = G
refresh = r,R
reload_config = ctrl r,ctrl R

newest_stories = n
top_stories = t
best_stories = b
show_stories = d
show_newest_stories = D
ask_stories = a
jobs_stories = J

[settings]
cache = /home/socketubs/.pyhn/cache
cache_age = 5
# Refresh interval in minutes (default: 5. minimum: 1)
refresh_interval = 5
browser_cmd = __default__

[colors]
body = default|
focus = white,bold|dark cyan
footer = black|light gray
footer-error = dark red,bold|light gray
header = black,bold|light gray
title = dark red,bold|light gray
help = black,standout|dark cyan

Settings

  • cache_age is a minute indicator which say to CacheManager when cache is outdated
  • browser_cmd is a bash command which will be use to open links

Examples: :

browser_cmd = lynx __url__
browser_cmd = __default__
browser_cmd = w3m __url__
browser_cmd = echo "[INFO] Open with w3m: __url__" >> /tmp/pyhn.log && w3m __url__

Key bindings

You can set different key bindings for same action with a comma separator. Take a look at urwid input manual.

Colors

Colors options are designed like that: foreground|background|monochrome.

foreground

  • colors: ‘default’ (use the terminal’s default foreground), ‘black’, ‘dark red’, ‘dark green’, ‘brown’, ‘dark blue’, ‘dark magenta’, ‘dark cyan’, ‘light gray’, ‘dark gray’, ‘light red’, ‘light green’, ‘yellow’, ‘light blue’, ‘light magenta’, ‘light cyan’, ‘white’
  • settings: ‘bold’, ‘underline’, ‘blink’, ‘standout’

background

  • colors: ‘default’ (use the terminal’s default background), ‘black’, ‘dark red’, ‘dark green’, ‘brown’, ‘dark blue’, ‘dark magenta’, ‘dark cyan’, ‘light gray’

monochrome

  • settings : ‘bold’, ‘underline’, ‘blink’, ‘standout’

For more informations you can take a look at urwid manual.

License

License is MIT. See LICENSE.

pyhn's People

Contributors

foxboron avatar jianli avatar kubo39 avatar mrjbq7 avatar mrshu avatar toanant avatar toxinu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyhn's Issues

Read comments in the terminal

Would be nice if we could read the comments in the terminal. Or at least have a key to open the comments page in the browser

Unable to install with python3, distribute and cygwin

$ easy_install pyhn
Searching for pyhn
Reading http://pypi.python.org/simple/pyhn/
Reading https://github.com/socketubs/pyhn/
Best match: pyhn 0.1.5
Downloading http://pypi.python.org/packages/source/p/pyhn/pyhn-0.1.5.tar.gz#md5=612b684555b7e65260ea01e96dd219e3
Processing pyhn-0.1.5.tar.gz
Writing /tmp/easy_install-__tj7z/pyhn-0.1.5/setup.cfg
Running pyhn-0.1.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-__tj7z/pyhn-0.1.5/egg-dist-tmp-k1xoiz
  File "build/bdist.cygwin-1.7.17-i686/egg/pyhn/hnapi.py", line 313
    print str(self.number) + ": " + self.title
            ^
SyntaxError: invalid syntax

zip_safe flag not set; analyzing archive contents...
  File "/usr/lib/python3.2/site-packages/pyhn-0.1.5-py3.2.egg/pyhn/hnapi.py", line 313
    print str(self.number) + ": " + self.title
            ^
SyntaxError: invalid syntax

Adding pyhn 0.1.5 to easy-install.pth file
Installing pyhn script to /usr/bin

Installed /usr/lib/python3.2/site-packages/pyhn-0.1.5-py3.2.egg
Processing dependencies for pyhn
Searching for beautifulsoup
Reading http://pypi.python.org/simple/beautifulsoup/
Reading http://www.crummy.com/software/BeautifulSoup/
Reading http://www.crummy.com/software/BeautifulSoup/download/
Reading http://www.crummy.com/software/BeautifulSoup/bs3/
Reading http://www.crummy.com/software/BeautifulSoup/bs3/download/
Best match: BeautifulSoup 3.2.1
Downloading http://www.crummy.com/software/BeautifulSoup/download/3.x/BeautifulSoup-3.2.1.tar.gz
Processing BeautifulSoup-3.2.1.tar.gz
Writing /tmp/easy_install-b4f0d0/BeautifulSoup-3.2.1/setup.cfg
Running BeautifulSoup-3.2.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-b4f0d0/BeautifulSoup-3.2.1/egg-dist-tmp-4v_1k_
Traceback (most recent call last):
  File "/usr/bin/easy_install", line 9, in <module>
    load_entry_point('distribute==0.6.34', 'console_scripts', 'easy_install')()
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/easy_install.py", line 1937, in main
    with_ei_usage(lambda:
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/easy_install.py", line 1918, in with_ei_usage
    return f()
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/easy_install.py", line 1941, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
  File "/usr/lib/python3.2/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.2/distutils/dist.py", line 917, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.2/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/easy_install.py", line 358, in run
    self.easy_install(spec, not self.no_deps)
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/easy_install.py", line 598, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/easy_install.py", line 630, in install_item
    self.process_distribution(spec, dist, deps)
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/easy_install.py", line 682, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/pkg_resources.py", line 586, in resolve
    dist = best[req.key] = env.best_match(req, self, installer)
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/pkg_resources.py", line 832, in best_match
    return self.obtain(req, installer) # try and download/install
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/pkg_resources.py", line 844, in obtain
    return installer(requirement)
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/easy_install.py", line 598, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/easy_install.py", line 628, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/easy_install.py", line 823, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/easy_install.py", line 1103, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/easy_install.py", line 1089, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/sandbox.py", line 34, in run_setup
    lambda: exec(compile(open(
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/sandbox.py", line 82, in run
    return func()
  File "/usr/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/sandbox.py", line 36, in <lambda>
    ).read(), "setup.py", 'exec'),
  File "setup.py", line 22
    print "Unit tests have failed!"
                                  ^
SyntaxError: invalid syntax

ValueError: invalid literal for int() with base 10: 'comments'

Hi there,

I'm getting an error when trying to launch pyhn:

Traceback (most recent call last):
  File "/usr/local/bin/pyhn", line 6, in <module>
    cachemanager = CacheManager()
  File "/usr/local/lib/python2.7/dist-packages/pyhn/cachemanager.py", line 23, in __init__
    self.refresh()
  File "/usr/local/lib/python2.7/dist-packages/pyhn/cachemanager.py", line 44, in refresh
    stories = self.api.getTopStories(extra_page=self.extra_page)
  File "/usr/local/lib/python2.7/dist-packages/pyhn/hnapi.py", line 300, in getTopStories
    stories += self.getStories(source_latest)
  File "/usr/local/lib/python2.7/dist-packages/pyhn/hnapi.py", line 251, in getStories
    storyCommentCounts.append(self.getCommentCount(story))
  File "/usr/local/lib/python2.7/dist-packages/pyhn/hnapi.py", line 177, in getCommentCount
    return int(commentCountString)
ValueError: invalid literal for int() with base 10: 'comments'

Mouse click selection support?

It would be great if user can select news with mouse clicking, and then maybe just a double click to open news (as an alternative way to hit Enter).

Not sure how to accomplish this, but there are some console utilities like htop have mouse support, and is sometimes a convenient way.

Thanks!

Load more stories

Would it be possible to have pyhn load more stories than just 60?

I would love to be able to go through the entire pagination available.

Nothing shown in columns SCORE & COMMENTS

image

Columns SCORE & COMMENTS show nothing on the right when running pyhn.

FYI

  • Mac OS 10.11.6
  • Python 2.7.10
  • pyhn 0.3.7, Latest, install by git clone XXX.git & sudo python setup.py install

Jobs typo ("bobs") in cache manager

Sorry, I'm not at my computer or I'd link to this properly, but it looks like the jobs API call may have a problem working as there's a typo in the cache manger. In line 56 it references "bobs" not "jobs"

AttributeError: 'NoneType' object has no attribute 'group'

I seem to have the latest version of pyhn:

$ pip show pyhn

---
Metadata-Version: 2.0
Name: pyhn
Version: 0.3.7
Summary: Hacker News in your terminal
Home-page: https://github.com/toxinu/pyhn/
Author: Geoffrey Lehée
Author-email: [email protected]
Installer: pip
License: The MIT License (MIT)
Location: /usr/local/lib/python2.7/site-packages
Requires: urwid, beautifulsoup4, requests
Classifiers:

But I'm getting this error when I run it:

$ pyhn
Loading stories...
Traceback (most recent call last):
  File "/usr/local/bin/pyhn", line 9, in <module>
    hn_gui.main()
  File "/usr/local/lib/python2.7/site-packages/pyhn/gui.py", line 98, in main
    self.build_interface()
  File "/usr/local/lib/python2.7/site-packages/pyhn/gui.py", line 144, in build_interface
    self.cache_manager.refresh()
  File "/usr/local/lib/python2.7/site-packages/pyhn/cachemanager.py", line 43, in refresh
    stories = self.api.get_top_stories(extra_page=self.extra_page)
  File "/usr/local/lib/python2.7/site-packages/pyhn/hnapi.py", line 353, in get_top_stories
    stories += self.get_stories(source)
  File "/usr/local/lib/python2.7/site-packages/pyhn/hnapi.py", line 260, in get_stories
    story_published_time.append(self.get_published_time(story))
  File "/usr/local/lib/python2.7/site-packages/pyhn/hnapi.py", line 190, in get_published_time
    return results.group()
AttributeError: 'NoneType' object has no attribute 'group'

Windows support

Some people emails me about Windows support.
I don't have any Windows available to test it, so if you have Python skills, your help is welcome.

But I clearly won't support Windows by myself.
By the way, I think there are no many changes to do to get it working.

Broken when installed from PIP w/ Virtualenv

Trying to install from pip error'd with:

Downloading/unpacking pyhn
  Running setup.py egg_info for package pyhn
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/Users/sirn/.virtualenvs/default/build/pyhn/setup.py", line 32, in <module>
        license=open("LICENSE").read(),
    IOError: [Errno 2] No such file or directory: 'LICENSE'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 16, in <module>

  File "/Users/sirn/.virtualenvs/default/build/pyhn/setup.py", line 32, in <module>

    license=open("LICENSE").read(),

IOError: [Errno 2] No such file or directory: 'LICENSE'

Possible fix:

here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README')).read()
LICENSE = open(os.path.join(here, 'LICENSE')).read()

Auto refresh

Thinking about a feature to auto refresh every X minutes pyhn feed.

HNapi for comments

Add comments parsing in the Api module.
And think about tree display of comments in Pyhn.

Crash when the window is smaller than the list and you scroll past the top link

Traceback (most recent call last):
  File "/usr/bin/pyhn", line 8, in <module>
    hn_gui.main()
  File "/usr/lib/python2.7/site-packages/pyhn/gui.py", line 54, in main
    self.ui.run_wrapper(self.run)
  File "/usr/lib/python2.7/site-packages/urwid/raw_display.py", line 242, in run_wrapper
    return fn()
  File "/usr/lib/python2.7/site-packages/pyhn/gui.py", line 162, in run
    self.loop.run()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 270, in run
    self._run()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 337, in _run
    self.event_loop.run()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 708, in run
    self._loop()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 787, in _loop
    self._watch_files[fd]()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 388, in _update
    self.process_input(keys)
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 494, in process_input
    something_handled |= bool(self.unhandled_input(k))
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 540, in unhandled_input
    return self._unhandled_input(input)
  File "/usr/lib/python2.7/site-packages/pyhn/gui.py", line 137, in keystroke
    self.listbox.set_focus(self.walker.prev_position(self.listbox.focus_position))
  File "/usr/lib/python2.7/site-packages/urwid/listbox.py", line 195, in prev_position
    raise IndexError
IndexError

Fresh Breakage

$ pyhn
Traceback (most recent call last):
  File "/usr/local/bin/pyhn", line 8, in <module>
    hn_gui.main()
  File "/usr/local/lib/python2.7/dist-packages/pyhn/gui.py", line 85, in main
    self.build_interface()
  File "/usr/local/lib/python2.7/dist-packages/pyhn/gui.py", line 124, in build_interface
    self.cache_manager.refresh()
  File "/usr/local/lib/python2.7/dist-packages/pyhn/cachemanager.py", line 44, in refresh
    stories = self.api.getTopStories(extra_page=self.extra_page)
  File "/usr/local/lib/python2.7/dist-packages/pyhn/hnapi.py", line 307, in getTopStories
    stories += self.getStories(source_latest)
  File "/usr/local/lib/python2.7/dist-packages/pyhn/hnapi.py", line 240, in getStories
    storyNumber = self.getStoryNumber(story)
  File "/usr/local/lib/python2.7/dist-packages/pyhn/hnapi.py", line 101, in getStoryNumber
    return int(source[numberStart:numberEnd])
ValueError: invalid literal for int() with base 10: '<span class="rank">1'

Fails to run on Python 3.5

I'm aware that pyhn is not listed on PyPI as being run on Python 3.5. However, Python 3.5 is the current default Python version and it is the version that provides the Python interpreter on e.g. ArchLinux, so it would be sweet to have pyhn running on Python 3.5.

$ pyhn
Traceback (most recent call last):
  File "/usr/bin/pyhn", line 4, in <module>
    from pyhn.cachemanager import CacheManager
  File "/usr/lib/python3.5/site-packages/pyhn/cachemanager.py", line 7, in <module>
    from pyhn.hnapi import HackerNewsAPI
  File "/usr/lib/python3.5/site-packages/pyhn/hnapi.py", line 49, in <module>
    from pyhn.lib.bs4_py3 import BeautifulSoup
  File "/usr/lib/python3.5/site-packages/pyhn/lib/bs4_py3/__init__.py", line 30, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "/usr/lib/python3.5/site-packages/pyhn/lib/bs4_py3/builder/__init__.py", line 308, in <module>
    from . import _htmlparser
  File "/usr/lib/python3.5/site-packages/pyhn/lib/bs4_py3/builder/_htmlparser.py", line 7, in <module>
    from html.parser import (
ImportError: cannot import name 'HTMLParseError'
$

How can i install it in osx 10.8

This is awesome, But how can i install it in my Macbook ?

I install pip use homebrew, and run pip install pyhn

Then I find pyhn at /usr/local/lib/python2.7/site-packages/

but I can not run pyhn in my command line and run /usr/local/lib/python2.7/site-packages/pyhn/pyhn will raise

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/pyhn/pyhn", line 3, in <module>
    from pyhn import gui
ImportError: No module named pyhn

Search

It would be great if you could filter the article titles with
a search pattern.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.