basyura's blog

あしたになったらほんきだす。

vim で stream api

こうですか ><

function! stream#execute()
  let cmd  = "curl -s -u" . g:stream_username . ":" . g:stream_password 
            \ . " https://stream.twitter.com/1.1/statuses/sample.json"
  let proc = vimproc#plineopen2(cmd)

  while 1
    let content = proc.stdout.read_line()
    if content == ''
      sleep 1
      continue
    end
    let status  = webapi#json#decode(content)
    echo status.user.screen_name . ' ' .  status.text
    sleep 1
  endwhile
endfunction
let g:stream_username = "username"
let g:stream_password = "password"
call stream#execute()