diff options
| author | ryanss | 2015-03-07 23:59:00 -0400 |
|---|---|---|
| committer | ryanss | 2015-03-07 23:59:00 -0400 |
| commit | 559cdcd280bebe54b5b4f977a6c428d3abc3c995 (patch) | |
| tree | d4ee7e36d25d4b29dd3e7f57f5679b015fa182cb | |
| parent | a8749a73c4ca4f835c68253b89617e12cc7c9d8d (diff) | |
| download | vim-hn-559cdcd280bebe54b5b4f977a6c428d3abc3c995.tar.gz | |
Add text representation of poll results
| -rw-r--r-- | ftplugin/hackernews.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/ftplugin/hackernews.py b/ftplugin/hackernews.py index a055dba..4c84cb7 100644 --- a/ftplugin/hackernews.py +++ b/ftplugin/hackernews.py @@ -32,6 +32,8 @@ else: API_URL = "http://node-hnapi.herokuapp.com" MARKDOWN_URL = "http://fuckyeahmarkdown.com/go/?read=1&u=" +html = HTMLParser() + def bwrite(s): b = vim.current.buffer @@ -181,6 +183,15 @@ def link(external=False): if 'content' in item: bwrite("") print_content(item['content']) + if 'poll' in item: + bwrite("") + max_score = max((c['points'] for c in item['poll'])) + for c in item['poll']: + bwrite("%s (%d points)" + % (html.unescape(c['item']), c['points'])) + bar = int(80.0 * c['points'] / max_score) + bwrite("#"*bar) + bwrite("") bwrite("") bwrite("") if item['type'] == "comment": @@ -232,9 +243,6 @@ def recall_pos(): vim.current.window.cursor = (int(mark[0]), int(mark[1])) -html = HTMLParser() - - def print_content(content): for p in content.split("<p>"): if not p: |
