diff options
| author | ryanss | 2015-01-31 23:59:00 -0500 |
|---|---|---|
| committer | ryanss | 2015-01-31 23:59:00 -0500 |
| commit | d961a4cd27770135428c010d959871a4ed7be4ff (patch) | |
| tree | dc8e09fdcf5dbca04bf7c09ee2e496b68fdb833e | |
| parent | 3ca15e39af37a254003e922b5f42eb9944b69eed (diff) | |
| download | vim-hn-d961a4cd27770135428c010d959871a4ed7be4ff.tar.gz | |
Improve handling of Hacker News item links
| -rw-r--r-- | plugin/hackernews.py | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/plugin/hackernews.py b/plugin/hackernews.py index ec0ca40..7781d72 100644 --- a/plugin/hackernews.py +++ b/plugin/hackernews.py @@ -50,17 +50,20 @@ def hacker_news(): continue if item['type'] == "link" and item['url'][:4] == "http": line = "%s%d. %s (%s) [%d]" - line %= (" " if i+1 < 10 else "", i+1, item['title'], item['domain'], item['id']) + line %= (" " if i+1 < 10 else "", i+1, item['title'], + item['domain'], item['id']) bwrite(line) line = "%s%d points by %s %s | %d comments [%d]" - line %= (" "*4, item['points'], item['user'], item['time_ago'], item['comments_count'], item['id']) + line %= (" "*4, item['points'], item['user'], item['time_ago'], + item['comments_count'], item['id']) bwrite(line) elif item['type'] == "link": line = "%s%d. %s [%d]" line %= (" " if i+1 < 10 else "", i+1, item['title'], item['id']) bwrite(line) - line = "%s%d points by %s %s | %d comments [%d]" - line %= (" "*4, item['points'], item['user'], item['time_ago'], item['comments_count'], item['id']) + line = "%s%d points by %s %s | %d comments [%s]" + line %= (" "*4, item['points'], item['user'], item['time_ago'], + item['comments_count'], item['id']) bwrite(line) elif item['type'] == "job": line = "%s%d. %s [%d]" @@ -84,8 +87,9 @@ def hacker_news_link(): bwrite(item['title']) bwrite("Posted %s by %s" % (item['time_ago'], item['user'])) bwrite("%d Points / %d Comments" % (item['points'], item['comments_count'])) - for i, wrap in enumerate(textwrap.wrap("[%s]" % item['url'], width=80)): - bwrite(wrap) + if item['url'].find("item?id=") == 0: + item['url'] = "http://news.ycombinator.com/" + item['url'] + bwrite("[%s]" % item['url']) bwrite("") bwrite("") print_comments(item['comments']) @@ -113,6 +117,19 @@ def hacker_news_link(): url += b[i][:b[i].find("]")] url = url.replace(" ", "").replace("\n", "") vim.command("edit .hackernews") + + if url.find("http://news.ycombinator.com/item?id=") == 0: + id = url[url.find("item?id=")+8:] + item = json.loads(urllib2.urlopen(API_URL+"/item/"+id).read()) + bwrite(item['title']) + bwrite("Posted %s by %s" % (item['time_ago'], item['user'])) + bwrite("%d Points / %d Comments" % (item['points'], item['comments_count'])) + bwrite("[http://news.ycombinator.com/item?id=" + str(id) + "]") + bwrite("") + bwrite("") + print_comments(item['comments']) + return + content = urllib2.urlopen("http://fuckyeahmarkdown.com/go/?read=1&u="+url).read() for i, line in enumerate(content.split('\n')): if not line: |
