This was just a fun (and morbid) way to experiment with hacking on vim with Python.
If you have Vim compiled with Python and the Airline plugin installed, you should be able to just plop this into your vimrc
:
๐ก There is an updated version that works asynchronously below.
function! CovidUpdate()
python3 << EOF
from urllib import request
import json
import vim
def getCases():
country = "US"
res = request.urlopen("https://covid2019-api.herokuapp.com/country/%s" % country)
string = res.read().decode()
info = json.loads(string)[country]
vim.vars["response"] = "Country: %s | Confimred: %i | Deaths: %i | Recovered: %i " % (country, info["confirmed"], info["deaths"], info["recovered"])
getCases()
EOF
endfunction
call CovidUpdate()
" call airline#parts#define_function('foo', "CovidUpdate")
let g:airline_section_y = airline#section#create_right(['ffenc', response])
Thanks to this project for providing the API.
๐จ UPDATE ๐จ
Threading a bit of python via the vim module is actually really easy!
Updated version:
function! CovidUpdate()
python3 << EOF
from urllib import request
import threading
import json
import vim
def getCases():
country = "US"
res = request.urlopen("https://covid2019-api.herokuapp.com/country/%s" % country)
string = res.read().decode()
info = json.loads(string)[country]
vim.vars["airline_section_y"] = "Country: %s | Confimred: %i | Deaths: %i | Recovered: %i " % (country, info["confirmed"], info["deaths"], info["recovered"])
vim.async_call(getCases)
EOF
endfunction
call CovidUpdate()
Note, the last line in the previous section:
let g:airline_section_y = airline#section#create_right(['ffenc', response])
is no longer necessary since that variable is set in the Python code. ๐ง
Top comments (1)
The API seems to be a little buggy. It's returning zero cases in the US. Kinda nice :)