summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorryanss2015-01-05 23:59:00 -0500
committerryanss2015-01-05 23:59:00 -0500
commita7cff5c6d5f69bf1c262168432e3eb0e1be9369f (patch)
tree41906754b6e7c223ae218a61c75aa3ad03cc081e
downloadvim-hn-a7cff5c6d5f69bf1c262168432e3eb0e1be9369f.tar.gz
Initial commit
-rw-r--r--.gitignore1
-rw-r--r--plugin/hackernews.py26
-rw-r--r--plugin/hackernews.vim10
3 files changed, 37 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0d20b64
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.pyc
diff --git a/plugin/hackernews.py b/plugin/hackernews.py
new file mode 100644
index 0000000..f10b794
--- /dev/null
+++ b/plugin/hackernews.py
@@ -0,0 +1,26 @@
+import json
+import urllib2
+import vim
+
+
+API_URL = "http://node-hnapi.herokuapp.com"
+
+
+def hacker_news():
+ vim.command("edit -HackerNews-")
+ vim.command("setlocal noswapfile")
+ vim.command("setlocal nobuflisted")
+ vim.command("setlocal buftype=nofile")
+
+ b = vim.current.buffer
+ b[0] = "Hacker News"
+ b.append("===========")
+ b.append("")
+
+ news1 = json.loads(urllib2.urlopen(API_URL+"/news").read())
+ news2 = json.loads(urllib2.urlopen(API_URL+"/news2").read())
+ for i, item in enumerate(news1+news2):
+ line = "%d. %s (%d comments) [%d]"
+ line %= (i+1, item['title'], item['comments_count'], item['id'])
+ b.append(line)
+ b.append("")
diff --git a/plugin/hackernews.vim b/plugin/hackernews.vim
new file mode 100644
index 0000000..1edb19d
--- /dev/null
+++ b/plugin/hackernews.vim
@@ -0,0 +1,10 @@
+if !has('python')
+ echo "HackerNews.vim Error: Requires Vim compiled with +python"
+ finish
+endif
+
+" Import Python code
+let s:path = expand("<sfile>:p:h")
+execute "pyfile " . s:path . "/hackernews.py"
+
+command! HackerNews python hacker_news()