Conky setting get/show location info from (Pia) VPN server

Forum rules
Before you post please read how to get help
Post Reply
User avatar
Gruppo Sportivo
Level 3
Level 3
Posts: 138
Joined: Sun May 28, 2017 4:14 am
Location: Rotterdam (NL)

Conky setting get/show location info from (Pia) VPN server

Post by Gruppo Sportivo » Mon Oct 14, 2019 6:10 am

By adding (see code lines) in conky, I get information from the locations that Pia server is connecting to.
Set the interval to 300 seconds (5 minutes), but don't really need that interval, as long as I don't switch to another server.
What is advisable set the interval time to 0 or do I have to increase it to 7200 or more, for example.

Code: Select all

Land: $alignr ${execi 300 wget -qO- ipinfo.io 2> /dev/null | grep "country" | awk -F'"' '{print $4}'} 

Code: Select all

Stad: $alignr ${execi 300 wget -qO- ipinfo.io 2> /dev/null | grep "city" | awk -F'"' '{print $4}'} 

Code: Select all

Regio: $alignr ${execi 300 wget -qO- ipinfo.io 2> /dev/null | grep "region" | awk -F'"' '{print $4}'}
Image

User avatar
zcot
Level 5
Level 5
Posts: 545
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky setting get/show location info from (Pia) VPN server

Post by zcot » Wed Oct 16, 2019 12:53 pm

You can not use 0 because it is less than the update_interval variable, which is how these 'exec' functions are defined, so probably use a high number.

Instead, maybe you want to try something like $no_update:

Code: Select all

Land: $alignr ${no_update ${execi 300 wget -qO- ipinfo.io 2> /dev/null | grep "country" | awk -F'"' '{print $4}'}}
-so it will run once and not run after that.

edit: i guess that syntax was wrong

User avatar
Gruppo Sportivo
Level 3
Level 3
Posts: 138
Joined: Sun May 28, 2017 4:14 am
Location: Rotterdam (NL)

Re: Conky setting get/show location info from (Pia) VPN server

Post by Gruppo Sportivo » Thu Oct 17, 2019 3:11 pm

zcot wrote:
Wed Oct 16, 2019 12:53 pm

Code: Select all

Land: $alignr ${no_update ${execi 300 wget -qO- ipinfo.io 2> /dev/null | grep "country" | awk -F'"' '{print $4}'}}
edit: i guess that syntax was wrong
Thanks for your response but unfortunately you are right your code isn't working :wink:
I decided to set the interval in my own code to 60 seconds

User avatar
AndyMH
Level 9
Level 9
Posts: 2636
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Conky setting get/show location info from (Pia) VPN server

Post by AndyMH » Thu Oct 17, 2019 5:31 pm

Relevant line from my conky:

Code: Select all

Public IP: $alignr ${execi 43200 curl ifconfig.me/ip}
i.e. every 12 hours, but I don't expect my external IP to change.
Homebrew i5-8400+GTX1080 Cinnamon 19.0, 3 x Thinkpad T430 Cinnamon 19.0, i7-3632 , i5-3320, i5-3210, Thinkpad T60 19.0 Mate

User avatar
zcot
Level 5
Level 5
Posts: 545
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky setting get/show location info from (Pia) VPN server

Post by zcot » Thu Oct 17, 2019 11:26 pm

Yea, sorry, I didn't test that line. :roll:

But here, I scratched this one up, and actually tested it. :lol:

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. :wink:

And then maybe work out a stop/restart script for that conky in case the vpn has changed.

User avatar
Gruppo Sportivo
Level 3
Level 3
Posts: 138
Joined: Sun May 28, 2017 4:14 am
Location: Rotterdam (NL)

Re: Conky setting get/show location info from (Pia) VPN server

Post by Gruppo Sportivo » Sat Oct 19, 2019 5:36 am

zcot wrote:
Thu Oct 17, 2019 11:26 pm
I always feel creepy about seeing what appears to be more processing than needed. Although in this case, it is barely even perceptible.

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.
So I did a lua script and added the following to the conky config file:
I have attempted to combine those 3 lines in conky with 1 Wget request, so far this has not been successful,leave it there for now.
Your Lua script is well thought out and looks good to me,nice thinking

"I love it when a plan comes together!" - Kolonel John "Hannibal" Smith catchphrase

User avatar
zcot
Level 5
Level 5
Posts: 545
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky setting get/show location info from (Pia) VPN server

Post by zcot » Sun Oct 20, 2019 8:04 am

Maybe one day I will commit to learn about regex, but I always avoid it since I'm scared of it. :shock: Until then, I have to type out the longer form.

User avatar
Gruppo Sportivo
Level 3
Level 3
Posts: 138
Joined: Sun May 28, 2017 4:14 am
Location: Rotterdam (NL)

Re: Conky setting get/show location info from (Pia) VPN server

Post by Gruppo Sportivo » Sat Oct 26, 2019 6:41 am

The PIA server location brought back to 1 line in Conky

Code: Select all

Locatie server: $alignr ${execi 60 wget -qO- ipinfo.io 2> /dev/null | grep "city" | awk -F'"' '{print $4}'} - ${execi 60 wget -qO- ipinfo.io 2> /dev/null | grep "region" | awk -F'"' '{print $4}'} - ${execi 60 wget -qO- ipinfo.io 2> /dev/null | grep "country" | awk -F'"' '{print $4}'} 
Image

User avatar
zcot
Level 5
Level 5
Posts: 545
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky setting get/show location info from (Pia) VPN server

Post by zcot » Tue Oct 29, 2019 11:49 am

I did some messing around. One single execi call, and a single wget call. I have this:

Code: Select all

stad/regio/land:
${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="city": "|"region": "|"country": ")(\w+)'}

User avatar
AndyMH
Level 9
Level 9
Posts: 2636
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Conky setting get/show location info from (Pia) VPN server

Post by AndyMH » Tue Oct 29, 2019 6:16 pm

Thanks for that, I'll be amending my conky to show city/country.
Homebrew i5-8400+GTX1080 Cinnamon 19.0, 3 x Thinkpad T430 Cinnamon 19.0, i7-3632 , i5-3320, i5-3210, Thinkpad T60 19.0 Mate

User avatar
zcot
Level 5
Level 5
Posts: 545
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky setting get/show location info from (Pia) VPN server

Post by zcot » Wed Oct 30, 2019 6:16 pm

AndyMH, you are welcome! It was fun figuring out that much. :D

I'm weak with it, but I was able to get that far anyway. Not sure about efficiency though in comparison to other options like grep, sed, and awk, although that is faster than the other two examples from above. I'm guessing someone in the bash and scripts forum could do something like this with relative ease, and choose the most effective way to do it.

timing sample:

Code: Select all

elapsed time reg: 0.000006
elapsed time reg: 0.000010
elapsed time reg: 0.000009
And there's probably a simple way to format that output better, other than it coming out on 3 individual lines.

User avatar
AndyMH
Level 9
Level 9
Posts: 2636
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Conky setting get/show location info from (Pia) VPN server

Post by AndyMH » Wed Oct 30, 2019 7:03 pm

I'm ok with grep, usually, but when it comes to sed and awk I normally try and fail, try again, fail again (and this is after reading the man pages and searching the web). When I've done this several times, then I ask here and I've always had a rapid response. :)
Homebrew i5-8400+GTX1080 Cinnamon 19.0, 3 x Thinkpad T430 Cinnamon 19.0, i7-3632 , i5-3320, i5-3210, Thinkpad T60 19.0 Mate

User avatar
Gruppo Sportivo
Level 3
Level 3
Posts: 138
Joined: Sun May 28, 2017 4:14 am
Location: Rotterdam (NL)

Re: Conky setting get/show location info from (Pia) VPN server

Post by Gruppo Sportivo » Thu Oct 31, 2019 4:07 pm

zcot wrote:
Wed Oct 30, 2019 6:16 pm
And there's probably a simple way to format that output better, other than it coming out on 3 individual lines.
Thanks!
I changed the format to get the conky output in 1 line

Code: Select all

Locatie VPN Server: $alignr ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="city": ")(\w+)'} - ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="region": ")(\w+)'} - ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="country": ")(\w+)'}   

User avatar
zcot
Level 5
Level 5
Posts: 545
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky setting get/show location info from (Pia) VPN server

Post by zcot » Fri Nov 01, 2019 8:13 am

Gruppo Sportivo wrote:
Thu Oct 31, 2019 4:07 pm
zcot wrote:
Wed Oct 30, 2019 6:16 pm
And there's probably a simple way to format that output better, other than it coming out on 3 individual lines.
Thanks!
I changed the format to get the conky output in 1 line

Code: Select all

Locatie VPN Server: $alignr ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="city": ")(\w+)'} - ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="region": ")(\w+)'} - ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="country": ")(\w+)'}   
Yes! :wink:

Excellent, indeed! :D

Post Reply

Return to “Compiz, Conky, Docks, & Widgets”