Yea, sorry, I didn't test that line.
But here, I scratched this one up, and actually tested it.
I always feel creepy about seeing what appears to be more processing than needed. Although in this case, it is barely even perceptible. I did run timing on that code shown and the total of the 3 lines is averaging about 0.000022 microseconds on this test, so that feels good in the end.
But my thinking was, can we get away with only making the wget call once? and is that more effective? less usage? -and then pull each of the 3 pieces of info from that. To me, it "feels" better anyway. Although I admit sometimes I have tried to work something out and it only makes matters worse, but a lot of times it can be a nice addition. Or at least fun to work out the process, if nothing else.
So I did a lua script and added the following to the conky config file:
Code: Select all
${no_update ${lua conky_vpninfo}}\
Land: ${lua conky_vpn_get_country}
Stad: ${lua conky_vpn_get_city}
Regio: ${lua conky_vpn_get_state}
And in the
conky.config
section I have:
Code: Select all
conky.config = {
lua_load = 'vpninfo.lua',
...
And
vpninfo.lua
:
Code: Select all
local datat = {}
function conky_vpninfo()
local td = ""
local f = io.popen("wget -qO- ipinfo.io")
-- info is "parameter": "data", like json output so strip leading 2 quotes
for line in f:lines() do
td = td .. string.gsub(line, "\"", "", 2)
end
f:close()
-- also replace : with = and string can become functional lua table
datat = loadstring("return " .. string.gsub(td, ":", "="))()
return
end
function conky_vpn_get_country()
return tostring(datat.country)
end
function conky_vpn_get_state()
return tostring(datat.region)
end
function conky_vpn_get_city()
return tostring(datat.city)
end
suprisingly, these two blocks runs very close to the same amount of processing timings. Here are some timing samples:
Code: Select all
elapsed time raw: 0.000018
elapsed time lua: 0.000013
elapsed time raw: 0.000024
elapsed time lua: 0.000022
elapsed time raw: 0.000015
elapsed time lua: 0.000013
elapsed time raw: 0.000023
elapsed time lua: 0.000024
elapsed time raw: 0.000015
elapsed time lua: 0.000012
elapsed time raw: 0.000024
elapsed time lua: 0.000022
elapsed time raw: 0.000024
elapsed time lua: 0.000023
elapsed time raw: 0.000015
elapsed time lua: 0.000012
elapsed time raw: 0.000024
elapsed time lua: 0.000021
elapsed time raw: 0.000023
elapsed time lua: 0.000021
elapsed time raw: 0.000023
elapsed time lua: 0.000022
elapsed time raw: 0.000024
elapsed time lua: 0.000021
elapsed time raw: 0.000025
elapsed time lua: 0.000022
elapsed time raw: 0.000024
elapsed time lua: 0.000019
elapsed time raw: 0.000024
elapsed time lua: 0.000021
elapsed time raw: 0.000025
elapsed time lua: 0.000021
elapsed time raw: 0.000022
elapsed time lua: 0.000021
So, it was fun anyway.
And then maybe work out a stop/restart script for that conky in case the vpn has changed.