Skip to content

Instantly share code, notes, and snippets.

@suzuken
Created August 20, 2012 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suzuken/3404672 to your computer and use it in GitHub Desktop.
Save suzuken/3404672 to your computer and use it in GitHub Desktop.
ecnavi-vim-for-demo
" vim:set ts=2 sts=2 sw=2 tw=0:
scriptencoding utf-8
function! s:ecnavi_list(arg)
let winnum = bufwinnr(bufnr('^Ecnavi$'))
if winnum != -1
if winnum != bufwinnr('%')
exe winnum 'wincmd w'
endif
else
exec 'silent noautocmd split Ecnavi'
endif
setlocal modifiable
silent %d _
redraw | echo "fetching feed..."
call setline(1, map(webapi#feed#parseURL(a:arg), 'v:val["title"]." : ".v:val["link"]'))
setlocal buftype=nofile bufhidden=hide noswapfile
setlocal nomodified
setlocal nomodifiable
nmapclear <buffer>
syn clear
syntax match SpecialKey /[\x21-\x7f]\+$/
nnoremap <silent> <buffer> <cr> :call <SID>ecnavi_action()<cr>
exe "nnoremap <silent> <buffer> <leader><leader> :call <SID>ecnavi_list('".a:arg."')<cr>"
redraw | echo ""
endfunction
" action for clicking link on Ecnavi Window
function! s:ecnavi_action()
let line = getline('.')
echo line
call s:ecnavi(matchstr(line, '.* : \zshttp:\S\+\s*$'))
endfunction
function! s:ecnavi(arg)
if a:arg =~ '^\d\+$'
let url = 'http://shopping.ecnavi.com/item/%d', a:arg)
elseif a:arg =~ '^http://shopping.ecnavi.jp/item/\d\+/bbs?rid=\d\+$'
let url = matchstr(a:arg, 'http://shopping.ecnavi.jp/item/\d\+/bbs')
else
let url = a:arg
endif
setlocal modifiable
silent %d _
redraw | echo "fetching reviews..."
" http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fshopping.ecnavi.jp%2Fitem%2F10004660492462%2Fbbs%22%20and%20xpath%20%3D%20'%2F%2Fdiv%5B%40id%3D%22item_header%22%5D'&diagnostics=true
let yql_header = "select * from html where url ='" . url . "' and xpath = '//div[@id=\"item_header\"]'"
let res_header = webapi#http#get("http://query.yahooapis.com/v1/public/yql", {'q':yql_header})
redraw | echo "parsing header..."
let dom_header = webapi#xml#parse(res_header.content)
let essence_info = dom_header.childNode('results').childNode('div').find('div', {'class': 'essence_info'})
let title_clearfix = essence_info.find('div', {'class': 'title clearfix'}).childNode('div')
let brand = title_clearfix.childNode('p').value()
let h1 = title_clearfix.childNode('h1').value()
let lines = ['[' . brand . ' ' . h1 . ']']
let yql_comment = "select * from html where url ='" . url . "' and xpath = '//div[@class=\"review_unit gn_inner_frame space\"]'"
let res_comment = webapi#http#get("http://query.yahooapis.com/v1/public/yql", {'q':yql_comment})
redraw | echo "parsing comment..."
" 参考: http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url='http://shopping.ecnavi.jp/item/10004660492462/bbs'%20and%20xpath%20=%20'//div[@class=%22gn_contents_group%22]'
" http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url='http://shopping.ecnavi.jp/item/10004660492462/bbs'%20and%20xpath%20=%20'//div[@class=%22review_unit%20gn_inner_frame%20space%22]'
let dom_comment = webapi#xml#parse(res_comment.content)
for review in dom_comment.childNode('results').childNodes('div')
let review_header = review.childNode('div', {'class': 'header'})
let review_name = review_header.childNode('h3').childNode('a').value()
let review_poster = review_header.find('p', {'class': 'poster'}).find('span').value()
let review_group = review.find('div', {'class': 'group clearfix'})
let review_comment = review_group.childNode('div').childNode('p').value()
let text = substitute(review_comment, "\n", " ", "g")
let text = substitute(text, "^ *", "", "")
let lines += [review_poster]
let lines += [review_name]
let lines += [text]
let lines += ['------------------------------------']
endfor
let winnum = bufwinnr(bufnr('^Ecnavi$'))
if winnum != -1
if winnum != bufwinnr('%')
exe winnum 'wincmd w'
endif
else
exec 'silent noautocmd split Ecnavi'
endif
setlocal modifiable
silent %d _
call setline(1, lines)
setlocal buftype=nofile bufhidden=hide noswapfile
setlocal nomodified
setlocal nomodifiable
syn clear
syntax match Constant /^[a-zA-Z0-9_]*$/
syntax match SpecialKey /^-\+$/
syntax match Type /\<\(http\|https\|ftp\):\/\/[\x21-\x7f]\+/
syntax match WarningMsg /\%1l.*/
nmapclear <buffer>
exe "nnoremap <silent> <buffer> <leader><leader> :call <SID>ecnavi('".url."')<cr>"
redraw | echo ""
endfunction
command! -nargs=0 EcnaviReview call s:ecnavi_list('http://shopping.ecnavi.jp/rss/reviews.php')
command! -nargs=1 Ecnavi call s:ecnavi(<q-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment